1 //===----- SemaObjC.h ------ Semantic Analysis for Objective-C ------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 /// \file 9 /// This file declares semantic analysis for Objective-C. 10 /// 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_CLANG_SEMA_SEMAOBJC_H 14 #define LLVM_CLANG_SEMA_SEMAOBJC_H 15 16 #include "clang/AST/Decl.h" 17 #include "clang/AST/DeclBase.h" 18 #include "clang/AST/DeclObjC.h" 19 #include "clang/AST/Expr.h" 20 #include "clang/AST/ExprObjC.h" 21 #include "clang/AST/NSAPI.h" 22 #include "clang/AST/OperationKinds.h" 23 #include "clang/AST/Type.h" 24 #include "clang/Basic/IdentifierTable.h" 25 #include "clang/Basic/LLVM.h" 26 #include "clang/Basic/SourceLocation.h" 27 #include "clang/Basic/Specifiers.h" 28 #include "clang/Basic/TokenKinds.h" 29 #include "clang/Sema/DeclSpec.h" 30 #include "clang/Sema/Lookup.h" 31 #include "clang/Sema/ObjCMethodList.h" 32 #include "clang/Sema/Ownership.h" 33 #include "clang/Sema/Redeclaration.h" 34 #include "clang/Sema/Scope.h" 35 #include "clang/Sema/SemaBase.h" 36 #include "llvm/ADT/DenseMap.h" 37 #include "llvm/ADT/MapVector.h" 38 #include "llvm/ADT/SmallPtrSet.h" 39 #include <memory> 40 #include <optional> 41 #include <type_traits> 42 #include <utility> 43 44 namespace clang { 45 46 enum class CheckedConversionKind; 47 class ParsedAttr; 48 struct SkipBodyInfo; 49 50 class SemaObjC : public SemaBase { 51 public: 52 SemaObjC(Sema &S); 53 54 ExprResult CheckObjCForCollectionOperand(SourceLocation forLoc, 55 Expr *collection); 56 StmtResult ActOnObjCForCollectionStmt(SourceLocation ForColLoc, Stmt *First, 57 Expr *collection, 58 SourceLocation RParenLoc); 59 /// FinishObjCForCollectionStmt - Attach the body to a objective-C foreach 60 /// statement. 61 StmtResult FinishObjCForCollectionStmt(Stmt *ForCollection, Stmt *Body); 62 63 StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, 64 Decl *Parm, Stmt *Body); 65 66 StmtResult ActOnObjCAtFinallyStmt(SourceLocation AtLoc, Stmt *Body); 67 68 StmtResult ActOnObjCAtTryStmt(SourceLocation AtLoc, Stmt *Try, 69 MultiStmtArg Catch, Stmt *Finally); 70 71 StmtResult BuildObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw); 72 StmtResult ActOnObjCAtThrowStmt(SourceLocation AtLoc, Expr *Throw, 73 Scope *CurScope); 74 ExprResult ActOnObjCAtSynchronizedOperand(SourceLocation atLoc, 75 Expr *operand); 76 StmtResult ActOnObjCAtSynchronizedStmt(SourceLocation AtLoc, Expr *SynchExpr, 77 Stmt *SynchBody); 78 79 StmtResult ActOnObjCAutoreleasePoolStmt(SourceLocation AtLoc, Stmt *Body); 80 81 /// Build a an Objective-C protocol-qualified 'id' type where no 82 /// base type was specified. 83 TypeResult actOnObjCProtocolQualifierType( 84 SourceLocation lAngleLoc, ArrayRef<Decl *> protocols, 85 ArrayRef<SourceLocation> protocolLocs, SourceLocation rAngleLoc); 86 87 /// Build a specialized and/or protocol-qualified Objective-C type. 88 TypeResult actOnObjCTypeArgsAndProtocolQualifiers( 89 Scope *S, SourceLocation Loc, ParsedType BaseType, 90 SourceLocation TypeArgsLAngleLoc, ArrayRef<ParsedType> TypeArgs, 91 SourceLocation TypeArgsRAngleLoc, SourceLocation ProtocolLAngleLoc, 92 ArrayRef<Decl *> Protocols, ArrayRef<SourceLocation> ProtocolLocs, 93 SourceLocation ProtocolRAngleLoc); 94 95 /// Build an Objective-C type parameter type. 96 QualType BuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, 97 SourceLocation ProtocolLAngleLoc, 98 ArrayRef<ObjCProtocolDecl *> Protocols, 99 ArrayRef<SourceLocation> ProtocolLocs, 100 SourceLocation ProtocolRAngleLoc, 101 bool FailOnError = false); 102 103 /// Build an Objective-C object pointer type. 104 QualType BuildObjCObjectType( 105 QualType BaseType, SourceLocation Loc, SourceLocation TypeArgsLAngleLoc, 106 ArrayRef<TypeSourceInfo *> TypeArgs, SourceLocation TypeArgsRAngleLoc, 107 SourceLocation ProtocolLAngleLoc, ArrayRef<ObjCProtocolDecl *> Protocols, 108 ArrayRef<SourceLocation> ProtocolLocs, SourceLocation ProtocolRAngleLoc, 109 bool FailOnError, bool Rebuilding); 110 111 /// The parser has parsed the context-sensitive type 'instancetype' 112 /// in an Objective-C message declaration. Return the appropriate type. 113 ParsedType ActOnObjCInstanceType(SourceLocation Loc); 114 115 /// checkRetainCycles - Check whether an Objective-C message send 116 /// might create an obvious retain cycle. 117 void checkRetainCycles(ObjCMessageExpr *msg); 118 void checkRetainCycles(Expr *receiver, Expr *argument); 119 void checkRetainCycles(VarDecl *Var, Expr *Init); 120 121 bool CheckObjCString(Expr *Arg); 122 bool CheckObjCMethodCall(ObjCMethodDecl *Method, SourceLocation loc, 123 ArrayRef<const Expr *> Args); 124 /// Check whether receiver is mutable ObjC container which 125 /// attempts to add itself into the container 126 void CheckObjCCircularContainer(ObjCMessageExpr *Message); 127 128 void ActOnObjCContainerStartDefinition(ObjCContainerDecl *IDecl); 129 void ActOnObjCContainerFinishDefinition(); 130 131 /// Invoked when we must temporarily exit the objective-c container 132 /// scope for parsing/looking-up C constructs. 133 /// 134 /// Must be followed by a call to \see ActOnObjCReenterContainerContext 135 void ActOnObjCTemporaryExitContainerContext(ObjCContainerDecl *ObjCCtx); 136 void ActOnObjCReenterContainerContext(ObjCContainerDecl *ObjCCtx); 137 138 const DeclContext *getCurObjCLexicalContext() const; 139 140 ObjCProtocolDecl *LookupProtocol( 141 IdentifierInfo *II, SourceLocation IdLoc, 142 RedeclarationKind Redecl = RedeclarationKind::NotForRedeclaration); 143 144 bool isObjCWritebackConversion(QualType FromType, QualType ToType, 145 QualType &ConvertedType); 146 147 enum ObjCSubscriptKind { OS_Array, OS_Dictionary, OS_Error }; 148 ObjCSubscriptKind CheckSubscriptingKind(Expr *FromE); 149 150 /// AddCFAuditedAttribute - Check whether we're currently within 151 /// '\#pragma clang arc_cf_code_audited' and, if so, consider adding 152 /// the appropriate attribute. 153 void AddCFAuditedAttribute(Decl *D); 154 155 /// The struct behind the CFErrorRef pointer. 156 RecordDecl *CFError = nullptr; 157 bool isCFError(RecordDecl *D); 158 159 IdentifierInfo *getNSErrorIdent(); 160 161 bool GetFormatNSStringIdx(const FormatAttr *Format, unsigned &Idx); 162 163 /// Diagnose use of %s directive in an NSString which is being passed 164 /// as formatting string to formatting method. 165 void DiagnoseCStringFormatDirectiveInCFAPI(const NamedDecl *FDecl, 166 Expr **Args, unsigned NumArgs); 167 168 bool isSignedCharBool(QualType Ty); 169 170 void adornBoolConversionDiagWithTernaryFixit( 171 Expr *SourceExpr, const Sema::SemaDiagnosticBuilder &Builder); 172 173 /// Check an Objective-C dictionary literal being converted to the given 174 /// target type. 175 void checkDictionaryLiteral(QualType TargetType, 176 ObjCDictionaryLiteral *DictionaryLiteral); 177 178 /// Check an Objective-C array literal being converted to the given 179 /// target type. 180 void checkArrayLiteral(QualType TargetType, ObjCArrayLiteral *ArrayLiteral); 181 182 private: 183 IdentifierInfo *Ident_NSError = nullptr; 184 185 // 186 // 187 // ------------------------------------------------------------------------- 188 // 189 // 190 191 /// \name ObjC Declarations 192 /// Implementations are in SemaDeclObjC.cpp 193 ///@{ 194 195 public: 196 enum ObjCSpecialMethodKind { 197 OSMK_None, 198 OSMK_Alloc, 199 OSMK_New, 200 OSMK_Copy, 201 OSMK_RetainingInit, 202 OSMK_NonRetainingInit 203 }; 204 205 /// Method selectors used in a \@selector expression. Used for implementation 206 /// of -Wselector. 207 llvm::MapVector<Selector, SourceLocation> ReferencedSelectors; 208 209 class GlobalMethodPool { 210 public: 211 using Lists = std::pair<ObjCMethodList, ObjCMethodList>; 212 using iterator = llvm::DenseMap<Selector, Lists>::iterator; begin()213 iterator begin() { return Methods.begin(); } end()214 iterator end() { return Methods.end(); } find(Selector Sel)215 iterator find(Selector Sel) { return Methods.find(Sel); } insert(std::pair<Selector,Lists> && Val)216 std::pair<iterator, bool> insert(std::pair<Selector, Lists> &&Val) { 217 return Methods.insert(Val); 218 } count(Selector Sel)219 int count(Selector Sel) const { return Methods.count(Sel); } empty()220 bool empty() const { return Methods.empty(); } 221 222 private: 223 llvm::DenseMap<Selector, Lists> Methods; 224 }; 225 226 /// Method Pool - allows efficient lookup when typechecking messages to "id". 227 /// We need to maintain a list, since selectors can have differing signatures 228 /// across classes. In Cocoa, this happens to be extremely uncommon (only 1% 229 /// of selectors are "overloaded"). 230 /// At the head of the list it is recorded whether there were 0, 1, or >= 2 231 /// methods inside categories with a particular selector. 232 GlobalMethodPool MethodPool; 233 234 typedef llvm::SmallPtrSet<Selector, 8> SelectorSet; 235 236 enum MethodMatchStrategy { MMS_loose, MMS_strict }; 237 238 enum ObjCContainerKind { 239 OCK_None = -1, 240 OCK_Interface = 0, 241 OCK_Protocol, 242 OCK_Category, 243 OCK_ClassExtension, 244 OCK_Implementation, 245 OCK_CategoryImplementation 246 }; 247 ObjCContainerKind getObjCContainerKind() const; 248 249 DeclResult actOnObjCTypeParam(Scope *S, ObjCTypeParamVariance variance, 250 SourceLocation varianceLoc, unsigned index, 251 IdentifierInfo *paramName, 252 SourceLocation paramLoc, 253 SourceLocation colonLoc, ParsedType typeBound); 254 255 ObjCTypeParamList *actOnObjCTypeParamList(Scope *S, SourceLocation lAngleLoc, 256 ArrayRef<Decl *> typeParams, 257 SourceLocation rAngleLoc); 258 void popObjCTypeParamList(Scope *S, ObjCTypeParamList *typeParamList); 259 260 ObjCInterfaceDecl *ActOnStartClassInterface( 261 Scope *S, SourceLocation AtInterfaceLoc, IdentifierInfo *ClassName, 262 SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, 263 IdentifierInfo *SuperName, SourceLocation SuperLoc, 264 ArrayRef<ParsedType> SuperTypeArgs, SourceRange SuperTypeArgsRange, 265 Decl *const *ProtoRefs, unsigned NumProtoRefs, 266 const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc, 267 const ParsedAttributesView &AttrList, SkipBodyInfo *SkipBody); 268 269 void ActOnSuperClassOfClassInterface( 270 Scope *S, SourceLocation AtInterfaceLoc, ObjCInterfaceDecl *IDecl, 271 IdentifierInfo *ClassName, SourceLocation ClassLoc, 272 IdentifierInfo *SuperName, SourceLocation SuperLoc, 273 ArrayRef<ParsedType> SuperTypeArgs, SourceRange SuperTypeArgsRange); 274 275 void ActOnTypedefedProtocols(SmallVectorImpl<Decl *> &ProtocolRefs, 276 SmallVectorImpl<SourceLocation> &ProtocolLocs, 277 IdentifierInfo *SuperName, 278 SourceLocation SuperLoc); 279 280 Decl *ActOnCompatibilityAlias(SourceLocation AtCompatibilityAliasLoc, 281 IdentifierInfo *AliasName, 282 SourceLocation AliasLocation, 283 IdentifierInfo *ClassName, 284 SourceLocation ClassLocation); 285 286 bool CheckForwardProtocolDeclarationForCircularDependency( 287 IdentifierInfo *PName, SourceLocation &PLoc, SourceLocation PrevLoc, 288 const ObjCList<ObjCProtocolDecl> &PList); 289 290 ObjCProtocolDecl *ActOnStartProtocolInterface( 291 SourceLocation AtProtoInterfaceLoc, IdentifierInfo *ProtocolName, 292 SourceLocation ProtocolLoc, Decl *const *ProtoRefNames, 293 unsigned NumProtoRefs, const SourceLocation *ProtoLocs, 294 SourceLocation EndProtoLoc, const ParsedAttributesView &AttrList, 295 SkipBodyInfo *SkipBody); 296 297 ObjCCategoryDecl *ActOnStartCategoryInterface( 298 SourceLocation AtInterfaceLoc, const IdentifierInfo *ClassName, 299 SourceLocation ClassLoc, ObjCTypeParamList *typeParamList, 300 const IdentifierInfo *CategoryName, SourceLocation CategoryLoc, 301 Decl *const *ProtoRefs, unsigned NumProtoRefs, 302 const SourceLocation *ProtoLocs, SourceLocation EndProtoLoc, 303 const ParsedAttributesView &AttrList); 304 305 ObjCImplementationDecl *ActOnStartClassImplementation( 306 SourceLocation AtClassImplLoc, const IdentifierInfo *ClassName, 307 SourceLocation ClassLoc, const IdentifierInfo *SuperClassname, 308 SourceLocation SuperClassLoc, const ParsedAttributesView &AttrList); 309 310 ObjCCategoryImplDecl *ActOnStartCategoryImplementation( 311 SourceLocation AtCatImplLoc, const IdentifierInfo *ClassName, 312 SourceLocation ClassLoc, const IdentifierInfo *CatName, 313 SourceLocation CatLoc, const ParsedAttributesView &AttrList); 314 315 using DeclGroupPtrTy = OpaquePtr<DeclGroupRef>; 316 317 DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl, 318 ArrayRef<Decl *> Decls); 319 320 DeclGroupPtrTy 321 ActOnForwardProtocolDeclaration(SourceLocation AtProtoclLoc, 322 ArrayRef<IdentifierLocPair> IdentList, 323 const ParsedAttributesView &attrList); 324 325 void FindProtocolDeclaration(bool WarnOnDeclarations, bool ForObjCContainer, 326 ArrayRef<IdentifierLocPair> ProtocolId, 327 SmallVectorImpl<Decl *> &Protocols); 328 329 void DiagnoseTypeArgsAndProtocols(IdentifierInfo *ProtocolId, 330 SourceLocation ProtocolLoc, 331 IdentifierInfo *TypeArgId, 332 SourceLocation TypeArgLoc, 333 bool SelectProtocolFirst = false); 334 335 /// Given a list of identifiers (and their locations), resolve the 336 /// names to either Objective-C protocol qualifiers or type 337 /// arguments, as appropriate. 338 void actOnObjCTypeArgsOrProtocolQualifiers( 339 Scope *S, ParsedType baseType, SourceLocation lAngleLoc, 340 ArrayRef<IdentifierInfo *> identifiers, 341 ArrayRef<SourceLocation> identifierLocs, SourceLocation rAngleLoc, 342 SourceLocation &typeArgsLAngleLoc, SmallVectorImpl<ParsedType> &typeArgs, 343 SourceLocation &typeArgsRAngleLoc, SourceLocation &protocolLAngleLoc, 344 SmallVectorImpl<Decl *> &protocols, SourceLocation &protocolRAngleLoc, 345 bool warnOnIncompleteProtocols); 346 347 void DiagnoseClassExtensionDupMethods(ObjCCategoryDecl *CAT, 348 ObjCInterfaceDecl *ID); 349 350 Decl *ActOnAtEnd(Scope *S, SourceRange AtEnd, 351 ArrayRef<Decl *> allMethods = std::nullopt, 352 ArrayRef<DeclGroupPtrTy> allTUVars = std::nullopt); 353 354 struct ObjCArgInfo { 355 IdentifierInfo *Name; 356 SourceLocation NameLoc; 357 // The Type is null if no type was specified, and the DeclSpec is invalid 358 // in this case. 359 ParsedType Type; 360 ObjCDeclSpec DeclSpec; 361 362 /// ArgAttrs - Attribute list for this argument. 363 ParsedAttributesView ArgAttrs; 364 }; 365 366 Decl *ActOnMethodDeclaration( 367 Scope *S, 368 SourceLocation BeginLoc, // location of the + or -. 369 SourceLocation EndLoc, // location of the ; or {. 370 tok::TokenKind MethodType, ObjCDeclSpec &ReturnQT, ParsedType ReturnType, 371 ArrayRef<SourceLocation> SelectorLocs, Selector Sel, 372 // optional arguments. The number of types/arguments is obtained 373 // from the Sel.getNumArgs(). 374 ObjCArgInfo *ArgInfo, DeclaratorChunk::ParamInfo *CParamInfo, 375 unsigned CNumArgs, // c-style args 376 const ParsedAttributesView &AttrList, tok::ObjCKeywordKind MethodImplKind, 377 bool isVariadic, bool MethodDefinition); 378 379 bool CheckARCMethodDecl(ObjCMethodDecl *method); 380 381 bool checkInitMethod(ObjCMethodDecl *method, QualType receiverTypeIfCall); 382 383 /// Check whether the given new method is a valid override of the 384 /// given overridden method, and set any properties that should be inherited. 385 void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod, 386 const ObjCMethodDecl *Overridden); 387 388 /// Describes the compatibility of a result type with its method. 389 enum ResultTypeCompatibilityKind { 390 RTC_Compatible, 391 RTC_Incompatible, 392 RTC_Unknown 393 }; 394 395 void CheckObjCMethodDirectOverrides(ObjCMethodDecl *method, 396 ObjCMethodDecl *overridden); 397 398 void CheckObjCMethodOverrides(ObjCMethodDecl *ObjCMethod, 399 ObjCInterfaceDecl *CurrentClass, 400 ResultTypeCompatibilityKind RTC); 401 402 /// AddAnyMethodToGlobalPool - Add any method, instance or factory to global 403 /// pool. 404 void AddAnyMethodToGlobalPool(Decl *D); 405 406 void ActOnStartOfObjCMethodDef(Scope *S, Decl *D); isObjCMethodDecl(Decl * D)407 bool isObjCMethodDecl(Decl *D) { return isa_and_nonnull<ObjCMethodDecl>(D); } 408 409 /// CheckImplementationIvars - This routine checks if the instance variables 410 /// listed in the implelementation match those listed in the interface. 411 void CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, 412 ObjCIvarDecl **Fields, unsigned nIvars, 413 SourceLocation Loc); 414 415 void WarnConflictingTypedMethods(ObjCMethodDecl *Method, 416 ObjCMethodDecl *MethodDecl, 417 bool IsProtocolMethodDecl); 418 419 void CheckConflictingOverridingMethod(ObjCMethodDecl *Method, 420 ObjCMethodDecl *Overridden, 421 bool IsProtocolMethodDecl); 422 423 /// WarnExactTypedMethods - This routine issues a warning if method 424 /// implementation declaration matches exactly that of its declaration. 425 void WarnExactTypedMethods(ObjCMethodDecl *Method, ObjCMethodDecl *MethodDecl, 426 bool IsProtocolMethodDecl); 427 428 /// MatchAllMethodDeclarations - Check methods declaraed in interface or 429 /// or protocol against those declared in their implementations. 430 void MatchAllMethodDeclarations( 431 const SelectorSet &InsMap, const SelectorSet &ClsMap, 432 SelectorSet &InsMapSeen, SelectorSet &ClsMapSeen, ObjCImplDecl *IMPDecl, 433 ObjCContainerDecl *IDecl, bool &IncompleteImpl, bool ImmediateClass, 434 bool WarnCategoryMethodImpl = false); 435 436 /// CheckCategoryVsClassMethodMatches - Checks that methods implemented in 437 /// category matches with those implemented in its primary class and 438 /// warns each time an exact match is found. 439 void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP); 440 441 /// ImplMethodsVsClassMethods - This is main routine to warn if any method 442 /// remains unimplemented in the class or category \@implementation. 443 void ImplMethodsVsClassMethods(Scope *S, ObjCImplDecl *IMPDecl, 444 ObjCContainerDecl *IDecl, 445 bool IncompleteImpl = false); 446 447 DeclGroupPtrTy ActOnForwardClassDeclaration( 448 SourceLocation Loc, IdentifierInfo **IdentList, SourceLocation *IdentLocs, 449 ArrayRef<ObjCTypeParamList *> TypeParamLists, unsigned NumElts); 450 451 /// MatchTwoMethodDeclarations - Checks if two methods' type match and returns 452 /// true, or false, accordingly. 453 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method, 454 const ObjCMethodDecl *PrevMethod, 455 MethodMatchStrategy strategy = MMS_strict); 456 457 /// Add the given method to the list of globally-known methods. 458 void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method); 459 460 void ReadMethodPool(Selector Sel); 461 void updateOutOfDateSelector(Selector Sel); 462 463 /// - Returns instance or factory methods in global method pool for 464 /// given selector. It checks the desired kind first, if none is found, and 465 /// parameter checkTheOther is set, it then checks the other kind. If no such 466 /// method or only one method is found, function returns false; otherwise, it 467 /// returns true. 468 bool 469 CollectMultipleMethodsInGlobalPool(Selector Sel, 470 SmallVectorImpl<ObjCMethodDecl *> &Methods, 471 bool InstanceFirst, bool CheckTheOther, 472 const ObjCObjectType *TypeBound = nullptr); 473 474 bool 475 AreMultipleMethodsInGlobalPool(Selector Sel, ObjCMethodDecl *BestMethod, 476 SourceRange R, bool receiverIdOrClass, 477 SmallVectorImpl<ObjCMethodDecl *> &Methods); 478 479 void 480 DiagnoseMultipleMethodInGlobalPool(SmallVectorImpl<ObjCMethodDecl *> &Methods, 481 Selector Sel, SourceRange R, 482 bool receiverIdOrClass); 483 484 const ObjCMethodDecl * 485 SelectorsForTypoCorrection(Selector Sel, QualType ObjectType = QualType()); 486 /// LookupImplementedMethodInGlobalPool - Returns the method which has an 487 /// implementation. 488 ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel); 489 490 void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID); 491 492 /// Checks that the Objective-C declaration is declared in the global scope. 493 /// Emits an error and marks the declaration as invalid if it's not declared 494 /// in the global scope. 495 bool CheckObjCDeclScope(Decl *D); 496 497 void ActOnDefs(Scope *S, Decl *TagD, SourceLocation DeclStart, 498 const IdentifierInfo *ClassName, 499 SmallVectorImpl<Decl *> &Decls); 500 501 VarDecl *BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType ExceptionType, 502 SourceLocation StartLoc, SourceLocation IdLoc, 503 const IdentifierInfo *Id, 504 bool Invalid = false); 505 506 Decl *ActOnObjCExceptionDecl(Scope *S, Declarator &D); 507 508 /// CollectIvarsToConstructOrDestruct - Collect those ivars which require 509 /// initialization. 510 void 511 CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI, 512 SmallVectorImpl<ObjCIvarDecl *> &Ivars); 513 514 void DiagnoseUseOfUnimplementedSelectors(); 515 516 /// DiagnoseUnusedBackingIvarInAccessor - Issue an 'unused' warning if ivar 517 /// which backs the property is not used in the property's accessor. 518 void DiagnoseUnusedBackingIvarInAccessor(Scope *S, 519 const ObjCImplementationDecl *ImplD); 520 521 /// GetIvarBackingPropertyAccessor - If method is a property setter/getter and 522 /// it property has a backing ivar, returns this ivar; otherwise, returns 523 /// NULL. It also returns ivar's property on success. 524 ObjCIvarDecl * 525 GetIvarBackingPropertyAccessor(const ObjCMethodDecl *Method, 526 const ObjCPropertyDecl *&PDecl) const; 527 528 /// AddInstanceMethodToGlobalPool - All instance methods in a translation 529 /// unit are added to a global pool. This allows us to efficiently associate 530 /// a selector with a method declaraation for purposes of typechecking 531 /// messages sent to "id" (where the class of the object is unknown). 532 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method, 533 bool impl = false) { 534 AddMethodToGlobalPool(Method, impl, /*instance*/ true); 535 } 536 537 /// AddFactoryMethodToGlobalPool - Same as above, but for factory methods. 538 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl = false) { 539 AddMethodToGlobalPool(Method, impl, /*instance*/ false); 540 } 541 542 QualType AdjustParameterTypeForObjCAutoRefCount(QualType T, 543 SourceLocation NameLoc, 544 TypeSourceInfo *TSInfo); 545 546 /// Look for an Objective-C class in the translation unit. 547 /// 548 /// \param Id The name of the Objective-C class we're looking for. If 549 /// typo-correction fixes this name, the Id will be updated 550 /// to the fixed name. 551 /// 552 /// \param IdLoc The location of the name in the translation unit. 553 /// 554 /// \param DoTypoCorrection If true, this routine will attempt typo correction 555 /// if there is no class with the given name. 556 /// 557 /// \returns The declaration of the named Objective-C class, or NULL if the 558 /// class could not be found. 559 ObjCInterfaceDecl *getObjCInterfaceDecl(const IdentifierInfo *&Id, 560 SourceLocation IdLoc, 561 bool TypoCorrection = false); 562 563 bool inferObjCARCLifetime(ValueDecl *decl); 564 565 /// SetIvarInitializers - This routine builds initialization ASTs for the 566 /// Objective-C implementation whose ivars need be initialized. 567 void SetIvarInitializers(ObjCImplementationDecl *ObjCImplementation); 568 569 Decl *ActOnIvar(Scope *S, SourceLocation DeclStart, Declarator &D, 570 Expr *BitWidth, tok::ObjCKeywordKind visibility); 571 572 ObjCContainerDecl *getObjCDeclContext() const; 573 574 private: 575 /// AddMethodToGlobalPool - Add an instance or factory method to the global 576 /// pool. See descriptoin of AddInstanceMethodToGlobalPool. 577 void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance); 578 579 /// LookupMethodInGlobalPool - Returns the instance or factory method and 580 /// optionally warns if there are multiple signatures. 581 ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R, 582 bool receiverIdOrClass, 583 bool instance); 584 585 ///@} 586 587 // 588 // 589 // ------------------------------------------------------------------------- 590 // 591 // 592 593 /// \name ObjC Expressions 594 /// Implementations are in SemaExprObjC.cpp 595 ///@{ 596 597 public: 598 /// Caches identifiers/selectors for NSFoundation APIs. 599 std::unique_ptr<NSAPI> NSAPIObj; 600 601 /// The declaration of the Objective-C NSNumber class. 602 ObjCInterfaceDecl *NSNumberDecl; 603 604 /// The declaration of the Objective-C NSValue class. 605 ObjCInterfaceDecl *NSValueDecl; 606 607 /// Pointer to NSNumber type (NSNumber *). 608 QualType NSNumberPointer; 609 610 /// Pointer to NSValue type (NSValue *). 611 QualType NSValuePointer; 612 613 /// The Objective-C NSNumber methods used to create NSNumber literals. 614 ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods]; 615 616 /// The declaration of the Objective-C NSString class. 617 ObjCInterfaceDecl *NSStringDecl; 618 619 /// Pointer to NSString type (NSString *). 620 QualType NSStringPointer; 621 622 /// The declaration of the stringWithUTF8String: method. 623 ObjCMethodDecl *StringWithUTF8StringMethod; 624 625 /// The declaration of the valueWithBytes:objCType: method. 626 ObjCMethodDecl *ValueWithBytesObjCTypeMethod; 627 628 /// The declaration of the Objective-C NSArray class. 629 ObjCInterfaceDecl *NSArrayDecl; 630 631 /// The declaration of the arrayWithObjects:count: method. 632 ObjCMethodDecl *ArrayWithObjectsMethod; 633 634 /// The declaration of the Objective-C NSDictionary class. 635 ObjCInterfaceDecl *NSDictionaryDecl; 636 637 /// The declaration of the dictionaryWithObjects:forKeys:count: method. 638 ObjCMethodDecl *DictionaryWithObjectsMethod; 639 640 /// id<NSCopying> type. 641 QualType QIDNSCopying; 642 643 /// will hold 'respondsToSelector:' 644 Selector RespondsToSelectorSel; 645 646 ExprResult HandleExprPropertyRefExpr(const ObjCObjectPointerType *OPT, 647 Expr *BaseExpr, SourceLocation OpLoc, 648 DeclarationName MemberName, 649 SourceLocation MemberLoc, 650 SourceLocation SuperLoc, 651 QualType SuperType, bool Super); 652 653 ExprResult ActOnClassPropertyRefExpr(const IdentifierInfo &receiverName, 654 const IdentifierInfo &propertyName, 655 SourceLocation receiverNameLoc, 656 SourceLocation propertyNameLoc); 657 658 // ParseObjCStringLiteral - Parse Objective-C string literals. 659 ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs, 660 ArrayRef<Expr *> Strings); 661 662 ExprResult BuildObjCStringLiteral(SourceLocation AtLoc, StringLiteral *S); 663 664 /// BuildObjCNumericLiteral - builds an ObjCBoxedExpr AST node for the 665 /// numeric literal expression. Type of the expression will be "NSNumber *" 666 /// or "id" if NSNumber is unavailable. 667 ExprResult BuildObjCNumericLiteral(SourceLocation AtLoc, Expr *Number); 668 ExprResult ActOnObjCBoolLiteral(SourceLocation AtLoc, SourceLocation ValueLoc, 669 bool Value); 670 ExprResult BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements); 671 672 /// BuildObjCBoxedExpr - builds an ObjCBoxedExpr AST node for the 673 /// '@' prefixed parenthesized expression. The type of the expression will 674 /// either be "NSNumber *", "NSString *" or "NSValue *" depending on the type 675 /// of ValueType, which is allowed to be a built-in numeric type, "char *", 676 /// "const char *" or C structure with attribute 'objc_boxable'. 677 ExprResult BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr); 678 679 ExprResult BuildObjCSubscriptExpression(SourceLocation RB, Expr *BaseExpr, 680 Expr *IndexExpr, 681 ObjCMethodDecl *getterMethod, 682 ObjCMethodDecl *setterMethod); 683 684 ExprResult 685 BuildObjCDictionaryLiteral(SourceRange SR, 686 MutableArrayRef<ObjCDictionaryElement> Elements); 687 688 ExprResult BuildObjCEncodeExpression(SourceLocation AtLoc, 689 TypeSourceInfo *EncodedTypeInfo, 690 SourceLocation RParenLoc); 691 692 ExprResult ParseObjCEncodeExpression(SourceLocation AtLoc, 693 SourceLocation EncodeLoc, 694 SourceLocation LParenLoc, ParsedType Ty, 695 SourceLocation RParenLoc); 696 697 /// ParseObjCSelectorExpression - Build selector expression for \@selector 698 ExprResult ParseObjCSelectorExpression(Selector Sel, SourceLocation AtLoc, 699 SourceLocation SelLoc, 700 SourceLocation LParenLoc, 701 SourceLocation RParenLoc, 702 bool WarnMultipleSelectors); 703 704 /// ParseObjCProtocolExpression - Build protocol expression for \@protocol 705 ExprResult ParseObjCProtocolExpression(IdentifierInfo *ProtocolName, 706 SourceLocation AtLoc, 707 SourceLocation ProtoLoc, 708 SourceLocation LParenLoc, 709 SourceLocation ProtoIdLoc, 710 SourceLocation RParenLoc); 711 712 ObjCMethodDecl *tryCaptureObjCSelf(SourceLocation Loc); 713 714 /// Describes the kind of message expression indicated by a message 715 /// send that starts with an identifier. 716 enum ObjCMessageKind { 717 /// The message is sent to 'super'. 718 ObjCSuperMessage, 719 /// The message is an instance message. 720 ObjCInstanceMessage, 721 /// The message is a class message, and the identifier is a type 722 /// name. 723 ObjCClassMessage 724 }; 725 726 ObjCMessageKind getObjCMessageKind(Scope *S, IdentifierInfo *Name, 727 SourceLocation NameLoc, bool IsSuper, 728 bool HasTrailingDot, 729 ParsedType &ReceiverType); 730 731 ExprResult ActOnSuperMessage(Scope *S, SourceLocation SuperLoc, Selector Sel, 732 SourceLocation LBracLoc, 733 ArrayRef<SourceLocation> SelectorLocs, 734 SourceLocation RBracLoc, MultiExprArg Args); 735 736 ExprResult BuildClassMessage(TypeSourceInfo *ReceiverTypeInfo, 737 QualType ReceiverType, SourceLocation SuperLoc, 738 Selector Sel, ObjCMethodDecl *Method, 739 SourceLocation LBracLoc, 740 ArrayRef<SourceLocation> SelectorLocs, 741 SourceLocation RBracLoc, MultiExprArg Args, 742 bool isImplicit = false); 743 744 ExprResult BuildClassMessageImplicit(QualType ReceiverType, 745 bool isSuperReceiver, SourceLocation Loc, 746 Selector Sel, ObjCMethodDecl *Method, 747 MultiExprArg Args); 748 749 ExprResult ActOnClassMessage(Scope *S, ParsedType Receiver, Selector Sel, 750 SourceLocation LBracLoc, 751 ArrayRef<SourceLocation> SelectorLocs, 752 SourceLocation RBracLoc, MultiExprArg Args); 753 754 ExprResult BuildInstanceMessage(Expr *Receiver, QualType ReceiverType, 755 SourceLocation SuperLoc, Selector Sel, 756 ObjCMethodDecl *Method, 757 SourceLocation LBracLoc, 758 ArrayRef<SourceLocation> SelectorLocs, 759 SourceLocation RBracLoc, MultiExprArg Args, 760 bool isImplicit = false); 761 762 ExprResult BuildInstanceMessageImplicit(Expr *Receiver, QualType ReceiverType, 763 SourceLocation Loc, Selector Sel, 764 ObjCMethodDecl *Method, 765 MultiExprArg Args); 766 767 ExprResult ActOnInstanceMessage(Scope *S, Expr *Receiver, Selector Sel, 768 SourceLocation LBracLoc, 769 ArrayRef<SourceLocation> SelectorLocs, 770 SourceLocation RBracLoc, MultiExprArg Args); 771 772 ExprResult BuildObjCBridgedCast(SourceLocation LParenLoc, 773 ObjCBridgeCastKind Kind, 774 SourceLocation BridgeKeywordLoc, 775 TypeSourceInfo *TSInfo, Expr *SubExpr); 776 777 ExprResult ActOnObjCBridgedCast(Scope *S, SourceLocation LParenLoc, 778 ObjCBridgeCastKind Kind, 779 SourceLocation BridgeKeywordLoc, 780 ParsedType Type, SourceLocation RParenLoc, 781 Expr *SubExpr); 782 783 void CheckTollFreeBridgeCast(QualType castType, Expr *castExpr); 784 785 void CheckObjCBridgeRelatedCast(QualType castType, Expr *castExpr); 786 787 bool CheckTollFreeBridgeStaticCast(QualType castType, Expr *castExpr, 788 CastKind &Kind); 789 790 bool checkObjCBridgeRelatedComponents(SourceLocation Loc, QualType DestType, 791 QualType SrcType, 792 ObjCInterfaceDecl *&RelatedClass, 793 ObjCMethodDecl *&ClassMethod, 794 ObjCMethodDecl *&InstanceMethod, 795 TypedefNameDecl *&TDNDecl, bool CfToNs, 796 bool Diagnose = true); 797 798 bool CheckObjCBridgeRelatedConversions(SourceLocation Loc, QualType DestType, 799 QualType SrcType, Expr *&SrcExpr, 800 bool Diagnose = true); 801 802 /// Private Helper predicate to check for 'self'. 803 bool isSelfExpr(Expr *RExpr); 804 bool isSelfExpr(Expr *RExpr, const ObjCMethodDecl *Method); 805 806 ObjCMethodDecl *LookupMethodInQualifiedType(Selector Sel, 807 const ObjCObjectPointerType *OPT, 808 bool IsInstance); 809 ObjCMethodDecl *LookupMethodInObjectType(Selector Sel, QualType Ty, 810 bool IsInstance); 811 812 bool isKnownName(StringRef name); 813 814 enum ARCConversionResult { ACR_okay, ACR_unbridged, ACR_error }; 815 816 /// Checks for invalid conversions and casts between 817 /// retainable pointers and other pointer kinds for ARC and Weak. 818 ARCConversionResult CheckObjCConversion(SourceRange castRange, 819 QualType castType, Expr *&op, 820 CheckedConversionKind CCK, 821 bool Diagnose = true, 822 bool DiagnoseCFAudited = false, 823 BinaryOperatorKind Opc = BO_PtrMemD); 824 825 Expr *stripARCUnbridgedCast(Expr *e); 826 void diagnoseARCUnbridgedCast(Expr *e); 827 828 bool CheckObjCARCUnavailableWeakConversion(QualType castType, 829 QualType ExprType); 830 831 /// CheckMessageArgumentTypes - Check types in an Obj-C message send. 832 /// \param Method - May be null. 833 /// \param [out] ReturnType - The return type of the send. 834 /// \return true iff there were any incompatible types. 835 bool CheckMessageArgumentTypes(const Expr *Receiver, QualType ReceiverType, 836 MultiExprArg Args, Selector Sel, 837 ArrayRef<SourceLocation> SelectorLocs, 838 ObjCMethodDecl *Method, bool isClassMessage, 839 bool isSuperMessage, SourceLocation lbrac, 840 SourceLocation rbrac, SourceRange RecRange, 841 QualType &ReturnType, ExprValueKind &VK); 842 843 /// Determine the result of a message send expression based on 844 /// the type of the receiver, the method expected to receive the message, 845 /// and the form of the message send. 846 QualType getMessageSendResultType(const Expr *Receiver, QualType ReceiverType, 847 ObjCMethodDecl *Method, bool isClassMessage, 848 bool isSuperMessage); 849 850 /// If the given expression involves a message send to a method 851 /// with a related result type, emit a note describing what happened. 852 void EmitRelatedResultTypeNote(const Expr *E); 853 854 /// Given that we had incompatible pointer types in a return 855 /// statement, check whether we're in a method with a related result 856 /// type, and if so, emit a note describing what happened. 857 void EmitRelatedResultTypeNoteForReturn(QualType destType); 858 859 /// LookupInstanceMethodInGlobalPool - Returns the method and warns if 860 /// there are multiple signatures. 861 ObjCMethodDecl * 862 LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R, 863 bool receiverIdOrClass = false) { 864 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, 865 /*instance*/ true); 866 } 867 868 /// LookupFactoryMethodInGlobalPool - Returns the method and warns if 869 /// there are multiple signatures. 870 ObjCMethodDecl * 871 LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R, 872 bool receiverIdOrClass = false) { 873 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass, 874 /*instance*/ false); 875 } 876 877 /// The parser has read a name in, and Sema has detected that we're currently 878 /// inside an ObjC method. Perform some additional checks and determine if we 879 /// should form a reference to an ivar. 880 /// 881 /// Ideally, most of this would be done by lookup, but there's 882 /// actually quite a lot of extra work involved. 883 DeclResult LookupIvarInObjCMethod(LookupResult &Lookup, Scope *S, 884 IdentifierInfo *II); 885 886 /// The parser has read a name in, and Sema has detected that we're currently 887 /// inside an ObjC method. Perform some additional checks and determine if we 888 /// should form a reference to an ivar. If so, build an expression referencing 889 /// that ivar. 890 ExprResult LookupInObjCMethod(LookupResult &LookUp, Scope *S, 891 IdentifierInfo *II, 892 bool AllowBuiltinCreation = false); 893 894 ExprResult BuildIvarRefExpr(Scope *S, SourceLocation Loc, ObjCIvarDecl *IV); 895 896 /// FindCompositeObjCPointerType - Helper method to find composite type of 897 /// two objective-c pointer types of the two input expressions. 898 QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS, 899 SourceLocation QuestionLoc); 900 901 bool CheckConversionToObjCLiteral(QualType DstType, Expr *&SrcExpr, 902 bool Diagnose = true); 903 904 /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals. 905 ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind); 906 907 ExprResult 908 ActOnObjCAvailabilityCheckExpr(llvm::ArrayRef<AvailabilitySpec> AvailSpecs, 909 SourceLocation AtLoc, SourceLocation RParen); 910 911 /// Prepare a conversion of the given expression to an ObjC object 912 /// pointer type. 913 CastKind PrepareCastToObjCObjectPointer(ExprResult &E); 914 915 // Note that LK_String is intentionally after the other literals, as 916 // this is used for diagnostics logic. 917 enum ObjCLiteralKind { 918 LK_Array, 919 LK_Dictionary, 920 LK_Numeric, 921 LK_Boxed, 922 LK_String, 923 LK_Block, 924 LK_None 925 }; 926 ObjCLiteralKind CheckLiteralKind(Expr *FromE); 927 928 ///@} 929 930 // 931 // 932 // ------------------------------------------------------------------------- 933 // 934 // 935 936 /// \name ObjC @property and @synthesize 937 /// Implementations are in SemaObjCProperty.cpp 938 ///@{ 939 940 public: 941 /// Ensure attributes are consistent with type. 942 /// \param [in, out] Attributes The attributes to check; they will 943 /// be modified to be consistent with \p PropertyTy. 944 void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, SourceLocation Loc, 945 unsigned &Attributes, 946 bool propertyInPrimaryClass); 947 948 /// Process the specified property declaration and create decls for the 949 /// setters and getters as needed. 950 /// \param property The property declaration being processed 951 void ProcessPropertyDecl(ObjCPropertyDecl *property); 952 953 Decl *ActOnProperty(Scope *S, SourceLocation AtLoc, SourceLocation LParenLoc, 954 FieldDeclarator &FD, ObjCDeclSpec &ODS, 955 Selector GetterSel, Selector SetterSel, 956 tok::ObjCKeywordKind MethodImplKind, 957 DeclContext *lexicalDC = nullptr); 958 959 Decl *ActOnPropertyImplDecl(Scope *S, SourceLocation AtLoc, 960 SourceLocation PropertyLoc, bool ImplKind, 961 IdentifierInfo *PropertyId, 962 IdentifierInfo *PropertyIvar, 963 SourceLocation PropertyIvarLoc, 964 ObjCPropertyQueryKind QueryKind); 965 966 /// Called by ActOnProperty to handle \@property declarations in 967 /// class extensions. 968 ObjCPropertyDecl *HandlePropertyInClassExtension( 969 Scope *S, SourceLocation AtLoc, SourceLocation LParenLoc, 970 FieldDeclarator &FD, Selector GetterSel, SourceLocation GetterNameLoc, 971 Selector SetterSel, SourceLocation SetterNameLoc, const bool isReadWrite, 972 unsigned &Attributes, const unsigned AttributesAsWritten, QualType T, 973 TypeSourceInfo *TSI, tok::ObjCKeywordKind MethodImplKind); 974 975 /// Called by ActOnProperty and HandlePropertyInClassExtension to 976 /// handle creating the ObjcPropertyDecl for a category or \@interface. 977 ObjCPropertyDecl * 978 CreatePropertyDecl(Scope *S, ObjCContainerDecl *CDecl, SourceLocation AtLoc, 979 SourceLocation LParenLoc, FieldDeclarator &FD, 980 Selector GetterSel, SourceLocation GetterNameLoc, 981 Selector SetterSel, SourceLocation SetterNameLoc, 982 const bool isReadWrite, const unsigned Attributes, 983 const unsigned AttributesAsWritten, QualType T, 984 TypeSourceInfo *TSI, tok::ObjCKeywordKind MethodImplKind, 985 DeclContext *lexicalDC = nullptr); 986 987 void DiagnosePropertyMismatch(ObjCPropertyDecl *Property, 988 ObjCPropertyDecl *SuperProperty, 989 const IdentifierInfo *Name, 990 bool OverridingProtocolProperty); 991 992 bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD, 993 ObjCMethodDecl *Getter, 994 SourceLocation Loc); 995 996 /// DiagnoseUnimplementedProperties - This routine warns on those properties 997 /// which must be implemented by this implementation. 998 void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl *IMPDecl, 999 ObjCContainerDecl *CDecl, 1000 bool SynthesizeProperties); 1001 1002 /// Diagnose any null-resettable synthesized setters. 1003 void diagnoseNullResettableSynthesizedSetters(const ObjCImplDecl *impDecl); 1004 1005 /// DefaultSynthesizeProperties - This routine default synthesizes all 1006 /// properties which must be synthesized in the class's \@implementation. 1007 void DefaultSynthesizeProperties(Scope *S, ObjCImplDecl *IMPDecl, 1008 ObjCInterfaceDecl *IDecl, 1009 SourceLocation AtEnd); 1010 void DefaultSynthesizeProperties(Scope *S, Decl *D, SourceLocation AtEnd); 1011 1012 /// IvarBacksCurrentMethodAccessor - This routine returns 'true' if 'IV' is 1013 /// an ivar synthesized for 'Method' and 'Method' is a property accessor 1014 /// declared in class 'IFace'. 1015 bool IvarBacksCurrentMethodAccessor(ObjCInterfaceDecl *IFace, 1016 ObjCMethodDecl *Method, ObjCIvarDecl *IV); 1017 1018 void DiagnoseOwningPropertyGetterSynthesis(const ObjCImplementationDecl *D); 1019 1020 void 1021 DiagnoseMissingDesignatedInitOverrides(const ObjCImplementationDecl *ImplD, 1022 const ObjCInterfaceDecl *IFD); 1023 1024 /// AtomicPropertySetterGetterRules - This routine enforces the rule (via 1025 /// warning) when atomic property has one but not the other user-declared 1026 /// setter or getter. 1027 void AtomicPropertySetterGetterRules(ObjCImplDecl *IMPDecl, 1028 ObjCInterfaceDecl *IDecl); 1029 1030 ///@} 1031 1032 // 1033 // 1034 // ------------------------------------------------------------------------- 1035 // 1036 // 1037 1038 /// \name ObjC Attributes 1039 /// Implementations are in SemaObjC.cpp 1040 ///@{ 1041 1042 bool isNSStringType(QualType T, bool AllowNSAttributedString = false); 1043 bool isCFStringType(QualType T); 1044 1045 void handleIBOutlet(Decl *D, const ParsedAttr &AL); 1046 void handleIBOutletCollection(Decl *D, const ParsedAttr &AL); 1047 1048 void handleSuppresProtocolAttr(Decl *D, const ParsedAttr &AL); 1049 void handleDirectAttr(Decl *D, const ParsedAttr &AL); 1050 void handleDirectMembersAttr(Decl *D, const ParsedAttr &AL); 1051 void handleMethodFamilyAttr(Decl *D, const ParsedAttr &AL); 1052 void handleNSObject(Decl *D, const ParsedAttr &AL); 1053 void handleIndependentClass(Decl *D, const ParsedAttr &AL); 1054 void handleBlocksAttr(Decl *D, const ParsedAttr &AL); 1055 void handleReturnsInnerPointerAttr(Decl *D, const ParsedAttr &Attrs); 1056 void handleXReturnsXRetainedAttr(Decl *D, const ParsedAttr &AL); 1057 void handleRequiresSuperAttr(Decl *D, const ParsedAttr &Attrs); 1058 void handleNSErrorDomain(Decl *D, const ParsedAttr &Attr); 1059 void handleBridgeAttr(Decl *D, const ParsedAttr &AL); 1060 void handleBridgeMutableAttr(Decl *D, const ParsedAttr &AL); 1061 void handleBridgeRelatedAttr(Decl *D, const ParsedAttr &AL); 1062 void handleDesignatedInitializer(Decl *D, const ParsedAttr &AL); 1063 void handleRuntimeName(Decl *D, const ParsedAttr &AL); 1064 void handleBoxable(Decl *D, const ParsedAttr &AL); 1065 void handleOwnershipAttr(Decl *D, const ParsedAttr &AL); 1066 void handlePreciseLifetimeAttr(Decl *D, const ParsedAttr &AL); 1067 void handleExternallyRetainedAttr(Decl *D, const ParsedAttr &AL); 1068 1069 void AddXConsumedAttr(Decl *D, const AttributeCommonInfo &CI, 1070 Sema::RetainOwnershipKind K, 1071 bool IsTemplateInstantiation); 1072 1073 /// \return whether the parameter is a pointer to OSObject pointer. 1074 bool isValidOSObjectOutParameter(const Decl *D); 1075 bool checkNSReturnsRetainedReturnType(SourceLocation loc, QualType type); 1076 1077 Sema::RetainOwnershipKind 1078 parsedAttrToRetainOwnershipKind(const ParsedAttr &AL); 1079 1080 ///@} 1081 }; 1082 1083 } // namespace clang 1084 1085 #endif // LLVM_CLANG_SEMA_SEMAOBJC_H 1086