File indexing completed on 2026-05-10 08:37:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
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
0062
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
0084
0085 TypeResult actOnObjCProtocolQualifierType(
0086 SourceLocation lAngleLoc, ArrayRef<Decl *> protocols,
0087 ArrayRef<SourceLocation> protocolLocs, SourceLocation rAngleLoc);
0088
0089
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
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
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
0114
0115 ParsedType ActOnObjCInstanceType(SourceLocation Loc);
0116
0117
0118
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
0127
0128 void CheckObjCCircularContainer(ObjCMessageExpr *Message);
0129
0130 void ActOnObjCContainerStartDefinition(ObjCContainerDecl *IDecl);
0131 void ActOnObjCContainerFinishDefinition();
0132
0133
0134
0135
0136
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
0153
0154
0155 void AddCFAuditedAttribute(Decl *D);
0156
0157
0158 RecordDecl *CFError = nullptr;
0159 bool isCFError(RecordDecl *D);
0160
0161 IdentifierInfo *getNSErrorIdent();
0162
0163 bool GetFormatNSStringIdx(const FormatAttr *Format, unsigned &Idx);
0164
0165
0166
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
0176
0177 void checkDictionaryLiteral(QualType TargetType,
0178 ObjCDictionaryLiteral *DictionaryLiteral);
0179
0180
0181
0182 void checkArrayLiteral(QualType TargetType, ObjCArrayLiteral *ArrayLiteral);
0183
0184 private:
0185 IdentifierInfo *Ident_NSError = nullptr;
0186
0187
0188
0189
0190
0191
0192
0193
0194
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
0208
0209 llvm::MapVector<Selector, SourceLocation> ReferencedSelectors;
0210
0211 using GlobalMethodPool =
0212 llvm::DenseMap<Selector, std::pair<ObjCMethodList, ObjCMethodList>>;
0213
0214
0215
0216
0217
0218
0219
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
0324
0325
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
0346
0347 ParsedType Type;
0348 ObjCDeclSpec DeclSpec;
0349
0350
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,
0361 SourceLocation EndLoc,
0362 tok::TokenKind MethodType, ObjCDeclSpec &ReturnQT, ParsedType ReturnType,
0363 ArrayRef<SourceLocation> SelectorLocs, Selector Sel,
0364
0365
0366 ParmVarDecl **ArgInfo, DeclaratorChunk::ParamInfo *CParamInfo,
0367 unsigned CNumArgs,
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
0376
0377 void CheckObjCMethodOverride(ObjCMethodDecl *NewMethod,
0378 const ObjCMethodDecl *Overridden);
0379
0380
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
0395
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
0402
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
0416
0417 void WarnExactTypedMethods(ObjCMethodDecl *Method, ObjCMethodDecl *MethodDecl,
0418 bool IsProtocolMethodDecl);
0419
0420
0421
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
0429
0430
0431 void CheckCategoryVsClassMethodMatches(ObjCCategoryImplDecl *CatIMP);
0432
0433
0434
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
0444
0445 bool MatchTwoMethodDeclarations(const ObjCMethodDecl *Method,
0446 const ObjCMethodDecl *PrevMethod,
0447 MethodMatchStrategy strategy = MMS_strict);
0448
0449
0450 void addMethodToGlobalList(ObjCMethodList *List, ObjCMethodDecl *Method);
0451
0452 void ReadMethodPool(Selector Sel);
0453 void updateOutOfDateSelector(Selector Sel);
0454
0455
0456
0457
0458
0459
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
0479
0480 ObjCMethodDecl *LookupImplementedMethodInGlobalPool(Selector Sel);
0481
0482 void DiagnoseDuplicateIvars(ObjCInterfaceDecl *ID, ObjCInterfaceDecl *SID);
0483
0484
0485
0486
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
0501
0502 void
0503 CollectIvarsToConstructOrDestruct(ObjCInterfaceDecl *OI,
0504 SmallVectorImpl<ObjCIvarDecl *> &Ivars);
0505
0506 void DiagnoseUseOfUnimplementedSelectors();
0507
0508
0509
0510 void DiagnoseUnusedBackingIvarInAccessor(Scope *S,
0511 const ObjCImplementationDecl *ImplD);
0512
0513
0514
0515
0516 ObjCIvarDecl *
0517 GetIvarBackingPropertyAccessor(const ObjCMethodDecl *Method,
0518 const ObjCPropertyDecl *&PDecl) const;
0519
0520
0521
0522
0523
0524 void AddInstanceMethodToGlobalPool(ObjCMethodDecl *Method,
0525 bool impl = false) {
0526 AddMethodToGlobalPool(Method, impl, true);
0527 }
0528
0529
0530 void AddFactoryMethodToGlobalPool(ObjCMethodDecl *Method, bool impl = false) {
0531 AddMethodToGlobalPool(Method, impl, false);
0532 }
0533
0534 QualType AdjustParameterTypeForObjCAutoRefCount(QualType T,
0535 SourceLocation NameLoc,
0536 TypeSourceInfo *TSInfo);
0537
0538
0539
0540
0541
0542
0543
0544
0545
0546
0547
0548
0549
0550
0551 ObjCInterfaceDecl *getObjCInterfaceDecl(const IdentifierInfo *&Id,
0552 SourceLocation IdLoc,
0553 bool TypoCorrection = false);
0554
0555 bool inferObjCARCLifetime(ValueDecl *decl);
0556
0557
0558
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
0568
0569 void AddMethodToGlobalPool(ObjCMethodDecl *Method, bool impl, bool instance);
0570
0571
0572
0573 ObjCMethodDecl *LookupMethodInGlobalPool(Selector Sel, SourceRange R,
0574 bool receiverIdOrClass,
0575 bool instance);
0576
0577
0578
0579
0580
0581
0582
0583
0584
0585
0586
0587
0588
0589 public:
0590
0591 std::unique_ptr<NSAPI> NSAPIObj;
0592
0593
0594 ObjCInterfaceDecl *NSNumberDecl;
0595
0596
0597 ObjCInterfaceDecl *NSValueDecl;
0598
0599
0600 QualType NSNumberPointer;
0601
0602
0603 QualType NSValuePointer;
0604
0605
0606 ObjCMethodDecl *NSNumberLiteralMethods[NSAPI::NumNSNumberLiteralMethods];
0607
0608
0609 ObjCInterfaceDecl *NSStringDecl;
0610
0611
0612 QualType NSStringPointer;
0613
0614
0615 ObjCMethodDecl *StringWithUTF8StringMethod;
0616
0617
0618 ObjCMethodDecl *ValueWithBytesObjCTypeMethod;
0619
0620
0621 ObjCInterfaceDecl *NSArrayDecl;
0622
0623
0624 ObjCMethodDecl *ArrayWithObjectsMethod;
0625
0626
0627 ObjCInterfaceDecl *NSDictionaryDecl;
0628
0629
0630 ObjCMethodDecl *DictionaryWithObjectsMethod;
0631
0632
0633 QualType QIDNSCopying;
0634
0635
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
0651 ExprResult ParseObjCStringLiteral(SourceLocation *AtLocs,
0652 ArrayRef<Expr *> Strings);
0653
0654 ExprResult BuildObjCStringLiteral(SourceLocation AtLoc, StringLiteral *S);
0655
0656
0657
0658
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
0665
0666
0667
0668
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
0690 ExprResult ParseObjCSelectorExpression(Selector Sel, SourceLocation AtLoc,
0691 SourceLocation SelLoc,
0692 SourceLocation LParenLoc,
0693 SourceLocation RParenLoc,
0694 bool WarnMultipleSelectors);
0695
0696
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
0707
0708 enum ObjCMessageKind {
0709
0710 ObjCSuperMessage,
0711
0712 ObjCInstanceMessage,
0713
0714
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
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
0809
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
0824
0825
0826
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
0836
0837
0838 QualType getMessageSendResultType(const Expr *Receiver, QualType ReceiverType,
0839 ObjCMethodDecl *Method, bool isClassMessage,
0840 bool isSuperMessage);
0841
0842
0843
0844 void EmitRelatedResultTypeNote(const Expr *E);
0845
0846
0847
0848
0849 void EmitRelatedResultTypeNoteForReturn(QualType destType);
0850
0851
0852
0853 ObjCMethodDecl *
0854 LookupInstanceMethodInGlobalPool(Selector Sel, SourceRange R,
0855 bool receiverIdOrClass = false) {
0856 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
0857 true);
0858 }
0859
0860
0861
0862 ObjCMethodDecl *
0863 LookupFactoryMethodInGlobalPool(Selector Sel, SourceRange R,
0864 bool receiverIdOrClass = false) {
0865 return LookupMethodInGlobalPool(Sel, R, receiverIdOrClass,
0866 false);
0867 }
0868
0869
0870
0871
0872
0873
0874
0875 DeclResult LookupIvarInObjCMethod(LookupResult &Lookup, Scope *S,
0876 IdentifierInfo *II);
0877
0878
0879
0880
0881
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
0889
0890 QualType FindCompositeObjCPointerType(ExprResult &LHS, ExprResult &RHS,
0891 SourceLocation QuestionLoc);
0892
0893 bool CheckConversionToObjCLiteral(QualType DstType, Expr *&SrcExpr,
0894 bool Diagnose = true);
0895
0896
0897 ExprResult ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind);
0898
0899 ExprResult
0900 ActOnObjCAvailabilityCheckExpr(llvm::ArrayRef<AvailabilitySpec> AvailSpecs,
0901 SourceLocation AtLoc, SourceLocation RParen);
0902
0903
0904
0905 CastKind PrepareCastToObjCObjectPointer(ExprResult &E);
0906
0907
0908
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
0929
0930
0931
0932 public:
0933
0934
0935
0936 void CheckObjCPropertyAttributes(Decl *PropertyPtrTy, SourceLocation Loc,
0937 unsigned &Attributes,
0938 bool propertyInPrimaryClass);
0939
0940
0941
0942
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
0959
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
0968
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
0989
0990 void DiagnoseUnimplementedProperties(Scope *S, ObjCImplDecl *IMPDecl,
0991 ObjCContainerDecl *CDecl,
0992 bool SynthesizeProperties);
0993
0994
0995 void diagnoseNullResettableSynthesizedSetters(const ObjCImplDecl *impDecl);
0996
0997
0998
0999 void DefaultSynthesizeProperties(Scope *S, ObjCImplDecl *IMPDecl,
1000 ObjCInterfaceDecl *IDecl,
1001 SourceLocation AtEnd);
1002 void DefaultSynthesizeProperties(Scope *S, Decl *D, SourceLocation AtEnd);
1003
1004
1005
1006
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
1017
1018
1019 void AtomicPropertySetterGetterRules(ObjCImplDecl *IMPDecl,
1020 ObjCInterfaceDecl *IDecl);
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
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
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 }
1076
1077 #endif