File indexing completed on 2026-05-10 08:36:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_CLANG_AST_DECLOBJC_H
0014 #define LLVM_CLANG_AST_DECLOBJC_H
0015
0016 #include "clang/AST/Decl.h"
0017 #include "clang/AST/DeclBase.h"
0018 #include "clang/AST/DeclObjCCommon.h"
0019 #include "clang/AST/ExternalASTSource.h"
0020 #include "clang/AST/Redeclarable.h"
0021 #include "clang/AST/SelectorLocationsKind.h"
0022 #include "clang/AST/Type.h"
0023 #include "clang/Basic/IdentifierTable.h"
0024 #include "clang/Basic/LLVM.h"
0025 #include "clang/Basic/SourceLocation.h"
0026 #include "clang/Basic/Specifiers.h"
0027 #include "llvm/ADT/ArrayRef.h"
0028 #include "llvm/ADT/DenseSet.h"
0029 #include "llvm/ADT/MapVector.h"
0030 #include "llvm/ADT/PointerIntPair.h"
0031 #include "llvm/ADT/STLExtras.h"
0032 #include "llvm/ADT/StringRef.h"
0033 #include "llvm/ADT/iterator_range.h"
0034 #include "llvm/Support/Compiler.h"
0035 #include "llvm/Support/TrailingObjects.h"
0036 #include <cassert>
0037 #include <cstddef>
0038 #include <cstdint>
0039 #include <iterator>
0040 #include <string>
0041 #include <utility>
0042
0043 namespace clang {
0044
0045 class ASTContext;
0046 class CompoundStmt;
0047 class CXXCtorInitializer;
0048 class Expr;
0049 class ObjCCategoryDecl;
0050 class ObjCCategoryImplDecl;
0051 class ObjCImplementationDecl;
0052 class ObjCInterfaceDecl;
0053 class ObjCIvarDecl;
0054 class ObjCPropertyDecl;
0055 class ObjCPropertyImplDecl;
0056 class ObjCProtocolDecl;
0057 class Stmt;
0058
0059 class ObjCListBase {
0060 protected:
0061
0062 void **List = nullptr;
0063 unsigned NumElts = 0;
0064
0065 public:
0066 ObjCListBase() = default;
0067 ObjCListBase(const ObjCListBase &) = delete;
0068 ObjCListBase &operator=(const ObjCListBase &) = delete;
0069
0070 unsigned size() const { return NumElts; }
0071 bool empty() const { return NumElts == 0; }
0072
0073 protected:
0074 void set(void *const* InList, unsigned Elts, ASTContext &Ctx);
0075 };
0076
0077
0078
0079
0080
0081 template <typename T>
0082 class ObjCList : public ObjCListBase {
0083 public:
0084 void set(T* const* InList, unsigned Elts, ASTContext &Ctx) {
0085 ObjCListBase::set(reinterpret_cast<void*const*>(InList), Elts, Ctx);
0086 }
0087
0088 using iterator = T* const *;
0089
0090 iterator begin() const { return (iterator)List; }
0091 iterator end() const { return (iterator)List+NumElts; }
0092
0093 T* operator[](unsigned Idx) const {
0094 assert(Idx < NumElts && "Invalid access");
0095 return (T*)List[Idx];
0096 }
0097 };
0098
0099
0100
0101 class ObjCProtocolList : public ObjCList<ObjCProtocolDecl> {
0102 SourceLocation *Locations = nullptr;
0103
0104 using ObjCList<ObjCProtocolDecl>::set;
0105
0106 public:
0107 ObjCProtocolList() = default;
0108
0109 using loc_iterator = const SourceLocation *;
0110
0111 loc_iterator loc_begin() const { return Locations; }
0112 loc_iterator loc_end() const { return Locations + size(); }
0113
0114 void set(ObjCProtocolDecl* const* InList, unsigned Elts,
0115 const SourceLocation *Locs, ASTContext &Ctx);
0116 };
0117
0118 enum class ObjCImplementationControl { None, Required, Optional };
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140 class ObjCMethodDecl : public NamedDecl, public DeclContext {
0141
0142
0143
0144
0145 QualType MethodDeclType;
0146
0147
0148 TypeSourceInfo *ReturnTInfo;
0149
0150
0151
0152 void *ParamsAndSelLocs = nullptr;
0153 unsigned NumParams = 0;
0154
0155
0156 SourceLocation DeclEndLoc;
0157
0158
0159 LazyDeclStmtPtr Body;
0160
0161
0162
0163 ImplicitParamDecl *SelfDecl = nullptr;
0164
0165
0166
0167 ImplicitParamDecl *CmdDecl = nullptr;
0168
0169 ObjCMethodDecl(
0170 SourceLocation beginLoc, SourceLocation endLoc, Selector SelInfo,
0171 QualType T, TypeSourceInfo *ReturnTInfo, DeclContext *contextDecl,
0172 bool isInstance = true, bool isVariadic = false,
0173 bool isPropertyAccessor = false, bool isSynthesizedAccessorStub = false,
0174 bool isImplicitlyDeclared = false, bool isDefined = false,
0175 ObjCImplementationControl impControl = ObjCImplementationControl::None,
0176 bool HasRelatedResultType = false);
0177
0178 SelectorLocationsKind getSelLocsKind() const {
0179 return static_cast<SelectorLocationsKind>(ObjCMethodDeclBits.SelLocsKind);
0180 }
0181
0182 void setSelLocsKind(SelectorLocationsKind Kind) {
0183 ObjCMethodDeclBits.SelLocsKind = Kind;
0184 }
0185
0186 bool hasStandardSelLocs() const {
0187 return getSelLocsKind() != SelLoc_NonStandard;
0188 }
0189
0190
0191
0192 SourceLocation *getStoredSelLocs() {
0193 return reinterpret_cast<SourceLocation *>(getParams() + NumParams);
0194 }
0195 const SourceLocation *getStoredSelLocs() const {
0196 return reinterpret_cast<const SourceLocation *>(getParams() + NumParams);
0197 }
0198
0199
0200
0201 ParmVarDecl **getParams() {
0202 return reinterpret_cast<ParmVarDecl **>(ParamsAndSelLocs);
0203 }
0204 const ParmVarDecl *const *getParams() const {
0205 return reinterpret_cast<const ParmVarDecl *const *>(ParamsAndSelLocs);
0206 }
0207
0208
0209
0210 unsigned getNumStoredSelLocs() const {
0211 if (hasStandardSelLocs())
0212 return 0;
0213 return getNumSelectorLocs();
0214 }
0215
0216 void setParamsAndSelLocs(ASTContext &C,
0217 ArrayRef<ParmVarDecl*> Params,
0218 ArrayRef<SourceLocation> SelLocs);
0219
0220
0221
0222
0223 ObjCMethodDecl *getNextRedeclarationImpl() override;
0224
0225 public:
0226 friend class ASTDeclReader;
0227 friend class ASTDeclWriter;
0228
0229 static ObjCMethodDecl *
0230 Create(ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc,
0231 Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo,
0232 DeclContext *contextDecl, bool isInstance = true,
0233 bool isVariadic = false, bool isPropertyAccessor = false,
0234 bool isSynthesizedAccessorStub = false,
0235 bool isImplicitlyDeclared = false, bool isDefined = false,
0236 ObjCImplementationControl impControl = ObjCImplementationControl::None,
0237 bool HasRelatedResultType = false);
0238
0239 static ObjCMethodDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
0240
0241 ObjCMethodDecl *getCanonicalDecl() override;
0242 const ObjCMethodDecl *getCanonicalDecl() const {
0243 return const_cast<ObjCMethodDecl*>(this)->getCanonicalDecl();
0244 }
0245
0246 ObjCDeclQualifier getObjCDeclQualifier() const {
0247 return static_cast<ObjCDeclQualifier>(ObjCMethodDeclBits.objcDeclQualifier);
0248 }
0249
0250 void setObjCDeclQualifier(ObjCDeclQualifier QV) {
0251 ObjCMethodDeclBits.objcDeclQualifier = QV;
0252 }
0253
0254
0255
0256 bool hasRelatedResultType() const {
0257 return ObjCMethodDeclBits.RelatedResultType;
0258 }
0259
0260
0261 void setRelatedResultType(bool RRT = true) {
0262 ObjCMethodDeclBits.RelatedResultType = RRT;
0263 }
0264
0265
0266 bool isRedeclaration() const { return ObjCMethodDeclBits.IsRedeclaration; }
0267 void setIsRedeclaration(bool RD) { ObjCMethodDeclBits.IsRedeclaration = RD; }
0268 void setAsRedeclaration(const ObjCMethodDecl *PrevMethod);
0269
0270
0271 bool hasRedeclaration() const { return ObjCMethodDeclBits.HasRedeclaration; }
0272 void setHasRedeclaration(bool HRD) const {
0273 ObjCMethodDeclBits.HasRedeclaration = HRD;
0274 }
0275
0276
0277
0278
0279 SourceLocation getDeclaratorEndLoc() const { return DeclEndLoc; }
0280
0281
0282 SourceLocation getBeginLoc() const LLVM_READONLY { return getLocation(); }
0283 SourceLocation getEndLoc() const LLVM_READONLY;
0284 SourceRange getSourceRange() const override LLVM_READONLY {
0285 return SourceRange(getLocation(), getEndLoc());
0286 }
0287
0288 SourceLocation getSelectorStartLoc() const {
0289 if (isImplicit())
0290 return getBeginLoc();
0291 return getSelectorLoc(0);
0292 }
0293
0294 SourceLocation getSelectorLoc(unsigned Index) const {
0295 assert(Index < getNumSelectorLocs() && "Index out of range!");
0296 if (hasStandardSelLocs())
0297 return getStandardSelectorLoc(Index, getSelector(),
0298 getSelLocsKind() == SelLoc_StandardWithSpace,
0299 parameters(),
0300 DeclEndLoc);
0301 return getStoredSelLocs()[Index];
0302 }
0303
0304 void getSelectorLocs(SmallVectorImpl<SourceLocation> &SelLocs) const;
0305
0306 unsigned getNumSelectorLocs() const {
0307 if (isImplicit())
0308 return 0;
0309 Selector Sel = getSelector();
0310 if (Sel.isUnarySelector())
0311 return 1;
0312 return Sel.getNumArgs();
0313 }
0314
0315 ObjCInterfaceDecl *getClassInterface();
0316 const ObjCInterfaceDecl *getClassInterface() const {
0317 return const_cast<ObjCMethodDecl*>(this)->getClassInterface();
0318 }
0319
0320
0321
0322 ObjCCategoryDecl *getCategory();
0323 const ObjCCategoryDecl *getCategory() const {
0324 return const_cast<ObjCMethodDecl*>(this)->getCategory();
0325 }
0326
0327 Selector getSelector() const { return getDeclName().getObjCSelector(); }
0328
0329 QualType getReturnType() const { return MethodDeclType; }
0330 void setReturnType(QualType T) { MethodDeclType = T; }
0331 SourceRange getReturnTypeSourceRange() const;
0332
0333
0334
0335
0336
0337 QualType getSendResultType() const;
0338
0339
0340
0341 QualType getSendResultType(QualType receiverType) const;
0342
0343 TypeSourceInfo *getReturnTypeSourceInfo() const { return ReturnTInfo; }
0344 void setReturnTypeSourceInfo(TypeSourceInfo *TInfo) { ReturnTInfo = TInfo; }
0345
0346
0347 unsigned param_size() const { return NumParams; }
0348
0349 using param_const_iterator = const ParmVarDecl *const *;
0350 using param_iterator = ParmVarDecl *const *;
0351 using param_range = llvm::iterator_range<param_iterator>;
0352 using param_const_range = llvm::iterator_range<param_const_iterator>;
0353
0354 param_const_iterator param_begin() const {
0355 return param_const_iterator(getParams());
0356 }
0357
0358 param_const_iterator param_end() const {
0359 return param_const_iterator(getParams() + NumParams);
0360 }
0361
0362 param_iterator param_begin() { return param_iterator(getParams()); }
0363 param_iterator param_end() { return param_iterator(getParams() + NumParams); }
0364
0365
0366
0367 param_const_iterator sel_param_end() const {
0368 return param_begin() + getSelector().getNumArgs();
0369 }
0370
0371
0372
0373 ArrayRef<ParmVarDecl*> parameters() const {
0374 return llvm::ArrayRef(const_cast<ParmVarDecl **>(getParams()), NumParams);
0375 }
0376
0377 ParmVarDecl *getParamDecl(unsigned Idx) {
0378 assert(Idx < NumParams && "Index out of bounds!");
0379 return getParams()[Idx];
0380 }
0381 const ParmVarDecl *getParamDecl(unsigned Idx) const {
0382 return const_cast<ObjCMethodDecl *>(this)->getParamDecl(Idx);
0383 }
0384
0385
0386
0387
0388 void setMethodParams(ASTContext &C, ArrayRef<ParmVarDecl *> Params,
0389 ArrayRef<SourceLocation> SelLocs = {});
0390
0391
0392 struct GetTypeFn {
0393 QualType operator()(const ParmVarDecl *PD) const { return PD->getType(); }
0394 };
0395
0396 using param_type_iterator =
0397 llvm::mapped_iterator<param_const_iterator, GetTypeFn>;
0398
0399 param_type_iterator param_type_begin() const {
0400 return llvm::map_iterator(param_begin(), GetTypeFn());
0401 }
0402
0403 param_type_iterator param_type_end() const {
0404 return llvm::map_iterator(param_end(), GetTypeFn());
0405 }
0406
0407
0408
0409
0410
0411 void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID);
0412
0413
0414
0415 QualType getSelfType(ASTContext &Context, const ObjCInterfaceDecl *OID,
0416 bool &selfIsPseudoStrong, bool &selfIsConsumed) const;
0417
0418 ImplicitParamDecl * getSelfDecl() const { return SelfDecl; }
0419 void setSelfDecl(ImplicitParamDecl *SD) { SelfDecl = SD; }
0420 ImplicitParamDecl * getCmdDecl() const { return CmdDecl; }
0421 void setCmdDecl(ImplicitParamDecl *CD) { CmdDecl = CD; }
0422
0423
0424 ObjCMethodFamily getMethodFamily() const;
0425
0426 bool isInstanceMethod() const { return ObjCMethodDeclBits.IsInstance; }
0427 void setInstanceMethod(bool isInst) {
0428 ObjCMethodDeclBits.IsInstance = isInst;
0429 }
0430
0431 bool isVariadic() const { return ObjCMethodDeclBits.IsVariadic; }
0432 void setVariadic(bool isVar) { ObjCMethodDeclBits.IsVariadic = isVar; }
0433
0434 bool isClassMethod() const { return !isInstanceMethod(); }
0435
0436 bool isPropertyAccessor() const {
0437 return ObjCMethodDeclBits.IsPropertyAccessor;
0438 }
0439
0440 void setPropertyAccessor(bool isAccessor) {
0441 ObjCMethodDeclBits.IsPropertyAccessor = isAccessor;
0442 }
0443
0444 bool isSynthesizedAccessorStub() const {
0445 return ObjCMethodDeclBits.IsSynthesizedAccessorStub;
0446 }
0447
0448 void setSynthesizedAccessorStub(bool isSynthesizedAccessorStub) {
0449 ObjCMethodDeclBits.IsSynthesizedAccessorStub = isSynthesizedAccessorStub;
0450 }
0451
0452 bool isDefined() const { return ObjCMethodDeclBits.IsDefined; }
0453 void setDefined(bool isDefined) { ObjCMethodDeclBits.IsDefined = isDefined; }
0454
0455
0456
0457
0458
0459
0460
0461
0462 bool isOverriding() const { return ObjCMethodDeclBits.IsOverriding; }
0463 void setOverriding(bool IsOver) { ObjCMethodDeclBits.IsOverriding = IsOver; }
0464
0465
0466
0467
0468
0469
0470
0471
0472
0473 void getOverriddenMethods(
0474 SmallVectorImpl<const ObjCMethodDecl *> &Overridden) const;
0475
0476
0477 bool hasSkippedBody() const { return ObjCMethodDeclBits.HasSkippedBody; }
0478 void setHasSkippedBody(bool Skipped = true) {
0479 ObjCMethodDeclBits.HasSkippedBody = Skipped;
0480 }
0481
0482
0483 bool isDirectMethod() const;
0484
0485
0486 bool hasParamDestroyedInCallee() const;
0487
0488
0489
0490
0491
0492
0493 const ObjCPropertyDecl *findPropertyDecl(bool CheckOverrides = true) const;
0494
0495
0496 void setDeclImplementation(ObjCImplementationControl ic) {
0497 ObjCMethodDeclBits.DeclImplementation = llvm::to_underlying(ic);
0498 }
0499
0500 ObjCImplementationControl getImplementationControl() const {
0501 return static_cast<ObjCImplementationControl>(
0502 ObjCMethodDeclBits.DeclImplementation);
0503 }
0504
0505 bool isOptional() const {
0506 return getImplementationControl() == ObjCImplementationControl::Optional;
0507 }
0508
0509
0510
0511 bool isThisDeclarationADesignatedInitializer() const;
0512
0513
0514
0515
0516
0517
0518
0519 bool isDesignatedInitializerForTheInterface(
0520 const ObjCMethodDecl **InitMethod = nullptr) const;
0521
0522
0523 bool hasBody() const override { return Body.isValid(); }
0524
0525
0526 Stmt *getBody() const override;
0527
0528 void setLazyBody(uint64_t Offset) { Body = Offset; }
0529
0530 CompoundStmt *getCompoundBody() { return (CompoundStmt*)getBody(); }
0531 void setBody(Stmt *B) { Body = B; }
0532
0533
0534 bool isThisDeclarationADefinition() const { return hasBody(); }
0535
0536
0537 bool definedInNSObject(const ASTContext &) const;
0538
0539
0540 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
0541 static bool classofKind(Kind K) { return K == ObjCMethod; }
0542
0543 static DeclContext *castToDeclContext(const ObjCMethodDecl *D) {
0544 return static_cast<DeclContext *>(const_cast<ObjCMethodDecl*>(D));
0545 }
0546
0547 static ObjCMethodDecl *castFromDeclContext(const DeclContext *DC) {
0548 return static_cast<ObjCMethodDecl *>(const_cast<DeclContext*>(DC));
0549 }
0550 };
0551
0552
0553 enum class ObjCTypeParamVariance : uint8_t {
0554
0555 Invariant,
0556
0557
0558
0559 Covariant,
0560
0561
0562
0563 Contravariant,
0564 };
0565
0566
0567
0568
0569
0570
0571
0572
0573
0574
0575
0576
0577
0578 class ObjCTypeParamDecl : public TypedefNameDecl {
0579
0580 unsigned Index : 14;
0581
0582
0583 LLVM_PREFERRED_TYPE(ObjCTypeParamVariance)
0584 unsigned Variance : 2;
0585
0586
0587 SourceLocation VarianceLoc;
0588
0589
0590
0591 SourceLocation ColonLoc;
0592
0593 ObjCTypeParamDecl(ASTContext &ctx, DeclContext *dc,
0594 ObjCTypeParamVariance variance, SourceLocation varianceLoc,
0595 unsigned index,
0596 SourceLocation nameLoc, IdentifierInfo *name,
0597 SourceLocation colonLoc, TypeSourceInfo *boundInfo)
0598 : TypedefNameDecl(ObjCTypeParam, ctx, dc, nameLoc, nameLoc, name,
0599 boundInfo),
0600 Index(index), Variance(static_cast<unsigned>(variance)),
0601 VarianceLoc(varianceLoc), ColonLoc(colonLoc) {}
0602
0603 void anchor() override;
0604
0605 public:
0606 friend class ASTDeclReader;
0607 friend class ASTDeclWriter;
0608
0609 static ObjCTypeParamDecl *Create(ASTContext &ctx, DeclContext *dc,
0610 ObjCTypeParamVariance variance,
0611 SourceLocation varianceLoc,
0612 unsigned index,
0613 SourceLocation nameLoc,
0614 IdentifierInfo *name,
0615 SourceLocation colonLoc,
0616 TypeSourceInfo *boundInfo);
0617 static ObjCTypeParamDecl *CreateDeserialized(ASTContext &ctx,
0618 GlobalDeclID ID);
0619
0620 SourceRange getSourceRange() const override LLVM_READONLY;
0621
0622
0623 ObjCTypeParamVariance getVariance() const {
0624 return static_cast<ObjCTypeParamVariance>(Variance);
0625 }
0626
0627
0628 void setVariance(ObjCTypeParamVariance variance) {
0629 Variance = static_cast<unsigned>(variance);
0630 }
0631
0632
0633 SourceLocation getVarianceLoc() const { return VarianceLoc; }
0634
0635
0636 unsigned getIndex() const { return Index; }
0637
0638
0639
0640 bool hasExplicitBound() const { return ColonLoc.isValid(); }
0641
0642
0643
0644 SourceLocation getColonLoc() const { return ColonLoc; }
0645
0646
0647 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
0648 static bool classofKind(Kind K) { return K == ObjCTypeParam; }
0649 };
0650
0651
0652
0653
0654
0655
0656
0657
0658 class ObjCTypeParamList final
0659 : private llvm::TrailingObjects<ObjCTypeParamList, ObjCTypeParamDecl *> {
0660
0661 SourceRange Brackets;
0662
0663 unsigned NumParams;
0664
0665 ObjCTypeParamList(SourceLocation lAngleLoc,
0666 ArrayRef<ObjCTypeParamDecl *> typeParams,
0667 SourceLocation rAngleLoc);
0668
0669 public:
0670 friend TrailingObjects;
0671
0672
0673 static ObjCTypeParamList *create(ASTContext &ctx,
0674 SourceLocation lAngleLoc,
0675 ArrayRef<ObjCTypeParamDecl *> typeParams,
0676 SourceLocation rAngleLoc);
0677
0678
0679 using iterator = ObjCTypeParamDecl **;
0680
0681 iterator begin() { return getTrailingObjects<ObjCTypeParamDecl *>(); }
0682
0683 iterator end() { return begin() + size(); }
0684
0685
0686 unsigned size() const { return NumParams; }
0687
0688
0689 using const_iterator = ObjCTypeParamDecl * const *;
0690
0691 const_iterator begin() const {
0692 return getTrailingObjects<ObjCTypeParamDecl *>();
0693 }
0694
0695 const_iterator end() const {
0696 return begin() + size();
0697 }
0698
0699 ObjCTypeParamDecl *front() const {
0700 assert(size() > 0 && "empty Objective-C type parameter list");
0701 return *begin();
0702 }
0703
0704 ObjCTypeParamDecl *back() const {
0705 assert(size() > 0 && "empty Objective-C type parameter list");
0706 return *(end() - 1);
0707 }
0708
0709 SourceLocation getLAngleLoc() const { return Brackets.getBegin(); }
0710 SourceLocation getRAngleLoc() const { return Brackets.getEnd(); }
0711 SourceRange getSourceRange() const { return Brackets; }
0712
0713
0714
0715 void gatherDefaultTypeArgs(SmallVectorImpl<QualType> &typeArgs) const;
0716 };
0717
0718 enum class ObjCPropertyQueryKind : uint8_t {
0719 OBJC_PR_query_unknown = 0x00,
0720 OBJC_PR_query_instance,
0721 OBJC_PR_query_class
0722 };
0723
0724
0725
0726
0727
0728
0729
0730 class ObjCPropertyDecl : public NamedDecl {
0731 void anchor() override;
0732
0733 public:
0734 enum SetterKind { Assign, Retain, Copy, Weak };
0735 enum PropertyControl { None, Required, Optional };
0736
0737 private:
0738
0739 SourceLocation AtLoc;
0740
0741
0742 SourceLocation LParenLoc;
0743
0744 QualType DeclType;
0745 TypeSourceInfo *DeclTypeSourceInfo;
0746 LLVM_PREFERRED_TYPE(ObjCPropertyAttribute::Kind)
0747 unsigned PropertyAttributes : NumObjCPropertyAttrsBits;
0748 LLVM_PREFERRED_TYPE(ObjCPropertyAttribute::Kind)
0749 unsigned PropertyAttributesAsWritten : NumObjCPropertyAttrsBits;
0750
0751
0752 LLVM_PREFERRED_TYPE(PropertyControl)
0753 unsigned PropertyImplementation : 2;
0754
0755
0756 Selector GetterName;
0757
0758
0759 Selector SetterName;
0760
0761
0762 SourceLocation GetterNameLoc;
0763
0764
0765 SourceLocation SetterNameLoc;
0766
0767
0768 ObjCMethodDecl *GetterMethodDecl = nullptr;
0769
0770
0771 ObjCMethodDecl *SetterMethodDecl = nullptr;
0772
0773
0774 ObjCIvarDecl *PropertyIvarDecl = nullptr;
0775
0776 ObjCPropertyDecl(DeclContext *DC, SourceLocation L, const IdentifierInfo *Id,
0777 SourceLocation AtLocation, SourceLocation LParenLocation,
0778 QualType T, TypeSourceInfo *TSI, PropertyControl propControl)
0779 : NamedDecl(ObjCProperty, DC, L, Id), AtLoc(AtLocation),
0780 LParenLoc(LParenLocation), DeclType(T), DeclTypeSourceInfo(TSI),
0781 PropertyAttributes(ObjCPropertyAttribute::kind_noattr),
0782 PropertyAttributesAsWritten(ObjCPropertyAttribute::kind_noattr),
0783 PropertyImplementation(propControl) {}
0784
0785 public:
0786 static ObjCPropertyDecl *Create(ASTContext &C, DeclContext *DC,
0787 SourceLocation L, const IdentifierInfo *Id,
0788 SourceLocation AtLocation,
0789 SourceLocation LParenLocation, QualType T,
0790 TypeSourceInfo *TSI,
0791 PropertyControl propControl = None);
0792
0793 static ObjCPropertyDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
0794
0795 SourceLocation getAtLoc() const { return AtLoc; }
0796 void setAtLoc(SourceLocation L) { AtLoc = L; }
0797
0798 SourceLocation getLParenLoc() const { return LParenLoc; }
0799 void setLParenLoc(SourceLocation L) { LParenLoc = L; }
0800
0801 TypeSourceInfo *getTypeSourceInfo() const { return DeclTypeSourceInfo; }
0802
0803 QualType getType() const { return DeclType; }
0804
0805 void setType(QualType T, TypeSourceInfo *TSI) {
0806 DeclType = T;
0807 DeclTypeSourceInfo = TSI;
0808 }
0809
0810
0811
0812 QualType getUsageType(QualType objectType) const;
0813
0814 ObjCPropertyAttribute::Kind getPropertyAttributes() const {
0815 return ObjCPropertyAttribute::Kind(PropertyAttributes);
0816 }
0817
0818 void setPropertyAttributes(ObjCPropertyAttribute::Kind PRVal) {
0819 PropertyAttributes |= PRVal;
0820 }
0821
0822 void overwritePropertyAttributes(unsigned PRVal) {
0823 PropertyAttributes = PRVal;
0824 }
0825
0826 ObjCPropertyAttribute::Kind getPropertyAttributesAsWritten() const {
0827 return ObjCPropertyAttribute::Kind(PropertyAttributesAsWritten);
0828 }
0829
0830 void setPropertyAttributesAsWritten(ObjCPropertyAttribute::Kind PRVal) {
0831 PropertyAttributesAsWritten = PRVal;
0832 }
0833
0834
0835
0836
0837 bool isReadOnly() const {
0838 return (PropertyAttributes & ObjCPropertyAttribute::kind_readonly);
0839 }
0840
0841
0842 bool isAtomic() const {
0843 return (PropertyAttributes & ObjCPropertyAttribute::kind_atomic);
0844 }
0845
0846
0847 bool isRetaining() const {
0848 return (PropertyAttributes & (ObjCPropertyAttribute::kind_retain |
0849 ObjCPropertyAttribute::kind_strong |
0850 ObjCPropertyAttribute::kind_copy));
0851 }
0852
0853 bool isInstanceProperty() const { return !isClassProperty(); }
0854 bool isClassProperty() const {
0855 return PropertyAttributes & ObjCPropertyAttribute::kind_class;
0856 }
0857 bool isDirectProperty() const;
0858
0859 ObjCPropertyQueryKind getQueryKind() const {
0860 return isClassProperty() ? ObjCPropertyQueryKind::OBJC_PR_query_class :
0861 ObjCPropertyQueryKind::OBJC_PR_query_instance;
0862 }
0863
0864 static ObjCPropertyQueryKind getQueryKind(bool isClassProperty) {
0865 return isClassProperty ? ObjCPropertyQueryKind::OBJC_PR_query_class :
0866 ObjCPropertyQueryKind::OBJC_PR_query_instance;
0867 }
0868
0869
0870
0871
0872 SetterKind getSetterKind() const {
0873 if (PropertyAttributes & ObjCPropertyAttribute::kind_strong)
0874 return getType()->isBlockPointerType() ? Copy : Retain;
0875 if (PropertyAttributes & ObjCPropertyAttribute::kind_retain)
0876 return Retain;
0877 if (PropertyAttributes & ObjCPropertyAttribute::kind_copy)
0878 return Copy;
0879 if (PropertyAttributes & ObjCPropertyAttribute::kind_weak)
0880 return Weak;
0881 return Assign;
0882 }
0883
0884 Selector getGetterName() const { return GetterName; }
0885 SourceLocation getGetterNameLoc() const { return GetterNameLoc; }
0886
0887 void setGetterName(Selector Sel, SourceLocation Loc = SourceLocation()) {
0888 GetterName = Sel;
0889 GetterNameLoc = Loc;
0890 }
0891
0892 Selector getSetterName() const { return SetterName; }
0893 SourceLocation getSetterNameLoc() const { return SetterNameLoc; }
0894
0895 void setSetterName(Selector Sel, SourceLocation Loc = SourceLocation()) {
0896 SetterName = Sel;
0897 SetterNameLoc = Loc;
0898 }
0899
0900 ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; }
0901 void setGetterMethodDecl(ObjCMethodDecl *gDecl) { GetterMethodDecl = gDecl; }
0902
0903 ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; }
0904 void setSetterMethodDecl(ObjCMethodDecl *gDecl) { SetterMethodDecl = gDecl; }
0905
0906
0907 void setPropertyImplementation(PropertyControl pc) {
0908 PropertyImplementation = pc;
0909 }
0910
0911 PropertyControl getPropertyImplementation() const {
0912 return PropertyControl(PropertyImplementation);
0913 }
0914
0915 bool isOptional() const {
0916 return getPropertyImplementation() == PropertyControl::Optional;
0917 }
0918
0919 void setPropertyIvarDecl(ObjCIvarDecl *Ivar) {
0920 PropertyIvarDecl = Ivar;
0921 }
0922
0923 ObjCIvarDecl *getPropertyIvarDecl() const {
0924 return PropertyIvarDecl;
0925 }
0926
0927 SourceRange getSourceRange() const override LLVM_READONLY {
0928 return SourceRange(AtLoc, getLocation());
0929 }
0930
0931
0932 IdentifierInfo *getDefaultSynthIvarName(ASTContext &Ctx) const;
0933
0934
0935 static ObjCPropertyDecl *findPropertyDecl(const DeclContext *DC,
0936 const IdentifierInfo *propertyID,
0937 ObjCPropertyQueryKind queryKind);
0938
0939 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
0940 static bool classofKind(Kind K) { return K == ObjCProperty; }
0941 };
0942
0943
0944
0945
0946
0947 class ObjCContainerDecl : public NamedDecl, public DeclContext {
0948
0949
0950
0951
0952
0953 SourceRange AtEnd;
0954
0955 void anchor() override;
0956
0957 public:
0958 ObjCContainerDecl(Kind DK, DeclContext *DC, const IdentifierInfo *Id,
0959 SourceLocation nameLoc, SourceLocation atStartLoc);
0960
0961
0962 using prop_iterator = specific_decl_iterator<ObjCPropertyDecl>;
0963 using prop_range =
0964 llvm::iterator_range<specific_decl_iterator<ObjCPropertyDecl>>;
0965
0966 prop_range properties() const { return prop_range(prop_begin(), prop_end()); }
0967
0968 prop_iterator prop_begin() const {
0969 return prop_iterator(decls_begin());
0970 }
0971
0972 prop_iterator prop_end() const {
0973 return prop_iterator(decls_end());
0974 }
0975
0976 using instprop_iterator =
0977 filtered_decl_iterator<ObjCPropertyDecl,
0978 &ObjCPropertyDecl::isInstanceProperty>;
0979 using instprop_range = llvm::iterator_range<instprop_iterator>;
0980
0981 instprop_range instance_properties() const {
0982 return instprop_range(instprop_begin(), instprop_end());
0983 }
0984
0985 instprop_iterator instprop_begin() const {
0986 return instprop_iterator(decls_begin());
0987 }
0988
0989 instprop_iterator instprop_end() const {
0990 return instprop_iterator(decls_end());
0991 }
0992
0993 using classprop_iterator =
0994 filtered_decl_iterator<ObjCPropertyDecl,
0995 &ObjCPropertyDecl::isClassProperty>;
0996 using classprop_range = llvm::iterator_range<classprop_iterator>;
0997
0998 classprop_range class_properties() const {
0999 return classprop_range(classprop_begin(), classprop_end());
1000 }
1001
1002 classprop_iterator classprop_begin() const {
1003 return classprop_iterator(decls_begin());
1004 }
1005
1006 classprop_iterator classprop_end() const {
1007 return classprop_iterator(decls_end());
1008 }
1009
1010
1011 using method_iterator = specific_decl_iterator<ObjCMethodDecl>;
1012 using method_range =
1013 llvm::iterator_range<specific_decl_iterator<ObjCMethodDecl>>;
1014
1015 method_range methods() const {
1016 return method_range(meth_begin(), meth_end());
1017 }
1018
1019 method_iterator meth_begin() const {
1020 return method_iterator(decls_begin());
1021 }
1022
1023 method_iterator meth_end() const {
1024 return method_iterator(decls_end());
1025 }
1026
1027 using instmeth_iterator =
1028 filtered_decl_iterator<ObjCMethodDecl,
1029 &ObjCMethodDecl::isInstanceMethod>;
1030 using instmeth_range = llvm::iterator_range<instmeth_iterator>;
1031
1032 instmeth_range instance_methods() const {
1033 return instmeth_range(instmeth_begin(), instmeth_end());
1034 }
1035
1036 instmeth_iterator instmeth_begin() const {
1037 return instmeth_iterator(decls_begin());
1038 }
1039
1040 instmeth_iterator instmeth_end() const {
1041 return instmeth_iterator(decls_end());
1042 }
1043
1044 using classmeth_iterator =
1045 filtered_decl_iterator<ObjCMethodDecl,
1046 &ObjCMethodDecl::isClassMethod>;
1047 using classmeth_range = llvm::iterator_range<classmeth_iterator>;
1048
1049 classmeth_range class_methods() const {
1050 return classmeth_range(classmeth_begin(), classmeth_end());
1051 }
1052
1053 classmeth_iterator classmeth_begin() const {
1054 return classmeth_iterator(decls_begin());
1055 }
1056
1057 classmeth_iterator classmeth_end() const {
1058 return classmeth_iterator(decls_end());
1059 }
1060
1061
1062 ObjCMethodDecl *getMethod(Selector Sel, bool isInstance,
1063 bool AllowHidden = false) const;
1064
1065 ObjCMethodDecl *getInstanceMethod(Selector Sel,
1066 bool AllowHidden = false) const {
1067 return getMethod(Sel, true, AllowHidden);
1068 }
1069
1070 ObjCMethodDecl *getClassMethod(Selector Sel, bool AllowHidden = false) const {
1071 return getMethod(Sel, false, AllowHidden);
1072 }
1073
1074 bool HasUserDeclaredSetterMethod(const ObjCPropertyDecl *P) const;
1075 ObjCIvarDecl *getIvarDecl(IdentifierInfo *Id) const;
1076
1077 ObjCPropertyDecl *getProperty(const IdentifierInfo *Id,
1078 bool IsInstance) const;
1079
1080 ObjCPropertyDecl *
1081 FindPropertyDeclaration(const IdentifierInfo *PropertyId,
1082 ObjCPropertyQueryKind QueryKind) const;
1083
1084 using PropertyMap =
1085 llvm::MapVector<std::pair<IdentifierInfo *, unsigned >,
1086 ObjCPropertyDecl *>;
1087 using ProtocolPropertySet = llvm::SmallDenseSet<const ObjCProtocolDecl *, 8>;
1088 using PropertyDeclOrder = llvm::SmallVector<ObjCPropertyDecl *, 8>;
1089
1090
1091
1092
1093 virtual void collectPropertiesToImplement(PropertyMap &PM) const {}
1094
1095 SourceLocation getAtStartLoc() const { return ObjCContainerDeclBits.AtStart; }
1096
1097 void setAtStartLoc(SourceLocation Loc) {
1098 ObjCContainerDeclBits.AtStart = Loc;
1099 }
1100
1101
1102 SourceRange getAtEndRange() const { return AtEnd; }
1103
1104 void setAtEndRange(SourceRange atEnd) { AtEnd = atEnd; }
1105
1106 SourceRange getSourceRange() const override LLVM_READONLY {
1107 return SourceRange(getAtStartLoc(), getAtEndRange().getEnd());
1108 }
1109
1110
1111 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1112
1113 static bool classofKind(Kind K) {
1114 return K >= firstObjCContainer &&
1115 K <= lastObjCContainer;
1116 }
1117
1118 static DeclContext *castToDeclContext(const ObjCContainerDecl *D) {
1119 return static_cast<DeclContext *>(const_cast<ObjCContainerDecl*>(D));
1120 }
1121
1122 static ObjCContainerDecl *castFromDeclContext(const DeclContext *DC) {
1123 return static_cast<ObjCContainerDecl *>(const_cast<DeclContext*>(DC));
1124 }
1125 };
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152 class ObjCInterfaceDecl : public ObjCContainerDecl
1153 , public Redeclarable<ObjCInterfaceDecl> {
1154 friend class ASTContext;
1155 friend class ODRDiagsEmitter;
1156
1157
1158
1159 mutable const Type *TypeForDecl = nullptr;
1160
1161 struct DefinitionData {
1162
1163
1164 ObjCInterfaceDecl *Definition = nullptr;
1165
1166
1167 TypeSourceInfo *SuperClassTInfo = nullptr;
1168
1169
1170 ObjCProtocolList ReferencedProtocols;
1171
1172
1173 ObjCList<ObjCProtocolDecl> AllReferencedProtocols;
1174
1175
1176
1177
1178
1179
1180 ObjCCategoryDecl *CategoryList = nullptr;
1181
1182
1183
1184 ObjCIvarDecl *IvarList = nullptr;
1185
1186
1187
1188 LLVM_PREFERRED_TYPE(bool)
1189 mutable unsigned ExternallyCompleted : 1;
1190
1191
1192
1193 LLVM_PREFERRED_TYPE(bool)
1194 mutable unsigned IvarListMissingImplementation : 1;
1195
1196
1197
1198 LLVM_PREFERRED_TYPE(bool)
1199 unsigned HasDesignatedInitializers : 1;
1200
1201 enum InheritedDesignatedInitializersState {
1202
1203
1204 IDI_Unknown = 0,
1205
1206
1207 IDI_Inherited = 1,
1208
1209
1210 IDI_NotInherited = 2
1211 };
1212
1213
1214 LLVM_PREFERRED_TYPE(InheritedDesignatedInitializersState)
1215 mutable unsigned InheritedDesignatedInitializers : 2;
1216
1217
1218 LLVM_PREFERRED_TYPE(bool)
1219 unsigned HasODRHash : 1;
1220
1221
1222 unsigned ODRHash = 0;
1223
1224
1225
1226
1227 SourceLocation EndLoc;
1228
1229 DefinitionData()
1230 : ExternallyCompleted(false), IvarListMissingImplementation(true),
1231 HasDesignatedInitializers(false),
1232 InheritedDesignatedInitializers(IDI_Unknown), HasODRHash(false) {}
1233 };
1234
1235
1236 ObjCTypeParamList *TypeParamList = nullptr;
1237
1238
1239
1240
1241
1242
1243 llvm::PointerIntPair<DefinitionData *, 1, bool> Data;
1244
1245 ObjCInterfaceDecl(const ASTContext &C, DeclContext *DC, SourceLocation AtLoc,
1246 const IdentifierInfo *Id, ObjCTypeParamList *typeParamList,
1247 SourceLocation CLoc, ObjCInterfaceDecl *PrevDecl,
1248 bool IsInternal);
1249
1250 void anchor() override;
1251
1252 void LoadExternalDefinition() const;
1253
1254 DefinitionData &data() const {
1255 assert(Data.getPointer() && "Declaration has no definition!");
1256 return *Data.getPointer();
1257 }
1258
1259
1260 void allocateDefinitionData();
1261
1262 using redeclarable_base = Redeclarable<ObjCInterfaceDecl>;
1263
1264 ObjCInterfaceDecl *getNextRedeclarationImpl() override {
1265 return getNextRedeclaration();
1266 }
1267
1268 ObjCInterfaceDecl *getPreviousDeclImpl() override {
1269 return getPreviousDecl();
1270 }
1271
1272 ObjCInterfaceDecl *getMostRecentDeclImpl() override {
1273 return getMostRecentDecl();
1274 }
1275
1276 public:
1277 static ObjCInterfaceDecl *
1278 Create(const ASTContext &C, DeclContext *DC, SourceLocation atLoc,
1279 const IdentifierInfo *Id, ObjCTypeParamList *typeParamList,
1280 ObjCInterfaceDecl *PrevDecl,
1281 SourceLocation ClassLoc = SourceLocation(), bool isInternal = false);
1282
1283 static ObjCInterfaceDecl *CreateDeserialized(const ASTContext &C,
1284 GlobalDeclID ID);
1285
1286
1287
1288
1289
1290
1291
1292 ObjCTypeParamList *getTypeParamList() const;
1293
1294
1295
1296
1297
1298 void setTypeParamList(ObjCTypeParamList *TPL);
1299
1300
1301
1302 ObjCTypeParamList *getTypeParamListAsWritten() const {
1303 return TypeParamList;
1304 }
1305
1306 SourceRange getSourceRange() const override LLVM_READONLY {
1307 if (isThisDeclarationADefinition())
1308 return ObjCContainerDecl::getSourceRange();
1309
1310 return SourceRange(getAtStartLoc(), getLocation());
1311 }
1312
1313
1314
1315
1316 void setExternallyCompleted();
1317
1318
1319
1320 void setHasDesignatedInitializers();
1321
1322
1323
1324 bool hasDesignatedInitializers() const;
1325
1326
1327
1328 bool declaresOrInheritsDesignatedInitializers() const {
1329 return hasDesignatedInitializers() || inheritsDesignatedInitializers();
1330 }
1331
1332 const ObjCProtocolList &getReferencedProtocols() const {
1333 assert(hasDefinition() && "Caller did not check for forward reference!");
1334 if (data().ExternallyCompleted)
1335 LoadExternalDefinition();
1336
1337 return data().ReferencedProtocols;
1338 }
1339
1340 ObjCImplementationDecl *getImplementation() const;
1341 void setImplementation(ObjCImplementationDecl *ImplD);
1342
1343 ObjCCategoryDecl *
1344 FindCategoryDeclaration(const IdentifierInfo *CategoryId) const;
1345
1346
1347 ObjCMethodDecl *getCategoryInstanceMethod(Selector Sel) const;
1348 ObjCMethodDecl *getCategoryClassMethod(Selector Sel) const;
1349
1350 ObjCMethodDecl *getCategoryMethod(Selector Sel, bool isInstance) const {
1351 return isInstance ? getCategoryInstanceMethod(Sel)
1352 : getCategoryClassMethod(Sel);
1353 }
1354
1355 using protocol_iterator = ObjCProtocolList::iterator;
1356 using protocol_range = llvm::iterator_range<protocol_iterator>;
1357
1358 protocol_range protocols() const {
1359 return protocol_range(protocol_begin(), protocol_end());
1360 }
1361
1362 protocol_iterator protocol_begin() const {
1363
1364 if (!hasDefinition())
1365 return protocol_iterator();
1366
1367 if (data().ExternallyCompleted)
1368 LoadExternalDefinition();
1369
1370 return data().ReferencedProtocols.begin();
1371 }
1372
1373 protocol_iterator protocol_end() const {
1374
1375 if (!hasDefinition())
1376 return protocol_iterator();
1377
1378 if (data().ExternallyCompleted)
1379 LoadExternalDefinition();
1380
1381 return data().ReferencedProtocols.end();
1382 }
1383
1384 using protocol_loc_iterator = ObjCProtocolList::loc_iterator;
1385 using protocol_loc_range = llvm::iterator_range<protocol_loc_iterator>;
1386
1387 protocol_loc_range protocol_locs() const {
1388 return protocol_loc_range(protocol_loc_begin(), protocol_loc_end());
1389 }
1390
1391 protocol_loc_iterator protocol_loc_begin() const {
1392
1393 if (!hasDefinition())
1394 return protocol_loc_iterator();
1395
1396 if (data().ExternallyCompleted)
1397 LoadExternalDefinition();
1398
1399 return data().ReferencedProtocols.loc_begin();
1400 }
1401
1402 protocol_loc_iterator protocol_loc_end() const {
1403
1404 if (!hasDefinition())
1405 return protocol_loc_iterator();
1406
1407 if (data().ExternallyCompleted)
1408 LoadExternalDefinition();
1409
1410 return data().ReferencedProtocols.loc_end();
1411 }
1412
1413 using all_protocol_iterator = ObjCList<ObjCProtocolDecl>::iterator;
1414 using all_protocol_range = llvm::iterator_range<all_protocol_iterator>;
1415
1416 all_protocol_range all_referenced_protocols() const {
1417 return all_protocol_range(all_referenced_protocol_begin(),
1418 all_referenced_protocol_end());
1419 }
1420
1421 all_protocol_iterator all_referenced_protocol_begin() const {
1422
1423 if (!hasDefinition())
1424 return all_protocol_iterator();
1425
1426 if (data().ExternallyCompleted)
1427 LoadExternalDefinition();
1428
1429 return data().AllReferencedProtocols.empty()
1430 ? protocol_begin()
1431 : data().AllReferencedProtocols.begin();
1432 }
1433
1434 all_protocol_iterator all_referenced_protocol_end() const {
1435
1436 if (!hasDefinition())
1437 return all_protocol_iterator();
1438
1439 if (data().ExternallyCompleted)
1440 LoadExternalDefinition();
1441
1442 return data().AllReferencedProtocols.empty()
1443 ? protocol_end()
1444 : data().AllReferencedProtocols.end();
1445 }
1446
1447 using ivar_iterator = specific_decl_iterator<ObjCIvarDecl>;
1448 using ivar_range = llvm::iterator_range<specific_decl_iterator<ObjCIvarDecl>>;
1449
1450 ivar_range ivars() const { return ivar_range(ivar_begin(), ivar_end()); }
1451
1452 ivar_iterator ivar_begin() const {
1453 if (const ObjCInterfaceDecl *Def = getDefinition())
1454 return ivar_iterator(Def->decls_begin());
1455
1456
1457 return ivar_iterator();
1458 }
1459
1460 ivar_iterator ivar_end() const {
1461 if (const ObjCInterfaceDecl *Def = getDefinition())
1462 return ivar_iterator(Def->decls_end());
1463
1464
1465 return ivar_iterator();
1466 }
1467
1468 unsigned ivar_size() const {
1469 return std::distance(ivar_begin(), ivar_end());
1470 }
1471
1472 bool ivar_empty() const { return ivar_begin() == ivar_end(); }
1473
1474 ObjCIvarDecl *all_declared_ivar_begin();
1475 const ObjCIvarDecl *all_declared_ivar_begin() const {
1476
1477
1478 return const_cast<ObjCInterfaceDecl *>(this)->all_declared_ivar_begin();
1479 }
1480 void setIvarList(ObjCIvarDecl *ivar) { data().IvarList = ivar; }
1481
1482
1483
1484 void setProtocolList(ObjCProtocolDecl *const* List, unsigned Num,
1485 const SourceLocation *Locs, ASTContext &C) {
1486 data().ReferencedProtocols.set(List, Num, Locs, C);
1487 }
1488
1489
1490
1491 void mergeClassExtensionProtocolList(ObjCProtocolDecl *const* List,
1492 unsigned Num,
1493 ASTContext &C);
1494
1495
1496
1497 StringRef getObjCRuntimeNameAsString() const;
1498
1499
1500
1501
1502
1503
1504 void getDesignatedInitializers(
1505 llvm::SmallVectorImpl<const ObjCMethodDecl *> &Methods) const;
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516 bool
1517 isDesignatedInitializer(Selector Sel,
1518 const ObjCMethodDecl **InitMethod = nullptr) const;
1519
1520
1521
1522 bool isThisDeclarationADefinition() const {
1523 return getDefinition() == this;
1524 }
1525
1526
1527 bool hasDefinition() const {
1528
1529
1530
1531
1532 if (!Data.getOpaqueValue())
1533 getMostRecentDecl();
1534
1535 return Data.getPointer();
1536 }
1537
1538
1539
1540
1541 ObjCInterfaceDecl *getDefinition() {
1542 return hasDefinition()? Data.getPointer()->Definition : nullptr;
1543 }
1544
1545
1546
1547
1548 const ObjCInterfaceDecl *getDefinition() const {
1549 return hasDefinition()? Data.getPointer()->Definition : nullptr;
1550 }
1551
1552
1553
1554 void startDefinition();
1555
1556
1557
1558
1559
1560 void startDuplicateDefinitionForComparison();
1561 void mergeDuplicateDefinitionWithCommon(const ObjCInterfaceDecl *Definition);
1562
1563
1564 const ObjCObjectType *getSuperClassType() const {
1565 if (TypeSourceInfo *TInfo = getSuperClassTInfo())
1566 return TInfo->getType()->castAs<ObjCObjectType>();
1567
1568 return nullptr;
1569 }
1570
1571
1572 TypeSourceInfo *getSuperClassTInfo() const {
1573
1574 if (!hasDefinition())
1575 return nullptr;
1576
1577 if (data().ExternallyCompleted)
1578 LoadExternalDefinition();
1579
1580 return data().SuperClassTInfo;
1581 }
1582
1583
1584
1585 ObjCInterfaceDecl *getSuperClass() const;
1586
1587 void setSuperClass(TypeSourceInfo *superClass) {
1588 data().SuperClassTInfo = superClass;
1589 }
1590
1591
1592
1593
1594
1595
1596 template<bool (*Filter)(ObjCCategoryDecl *)>
1597 class filtered_category_iterator {
1598 ObjCCategoryDecl *Current = nullptr;
1599
1600 void findAcceptableCategory();
1601
1602 public:
1603 using value_type = ObjCCategoryDecl *;
1604 using reference = value_type;
1605 using pointer = value_type;
1606 using difference_type = std::ptrdiff_t;
1607 using iterator_category = std::input_iterator_tag;
1608
1609 filtered_category_iterator() = default;
1610 explicit filtered_category_iterator(ObjCCategoryDecl *Current)
1611 : Current(Current) {
1612 findAcceptableCategory();
1613 }
1614
1615 reference operator*() const { return Current; }
1616 pointer operator->() const { return Current; }
1617
1618 filtered_category_iterator &operator++();
1619
1620 filtered_category_iterator operator++(int) {
1621 filtered_category_iterator Tmp = *this;
1622 ++(*this);
1623 return Tmp;
1624 }
1625
1626 friend bool operator==(filtered_category_iterator X,
1627 filtered_category_iterator Y) {
1628 return X.Current == Y.Current;
1629 }
1630
1631 friend bool operator!=(filtered_category_iterator X,
1632 filtered_category_iterator Y) {
1633 return X.Current != Y.Current;
1634 }
1635 };
1636
1637 private:
1638
1639
1640
1641 static bool isVisibleCategory(ObjCCategoryDecl *Cat);
1642
1643 public:
1644
1645
1646 using visible_categories_iterator =
1647 filtered_category_iterator<isVisibleCategory>;
1648
1649 using visible_categories_range =
1650 llvm::iterator_range<visible_categories_iterator>;
1651
1652 visible_categories_range visible_categories() const {
1653 return visible_categories_range(visible_categories_begin(),
1654 visible_categories_end());
1655 }
1656
1657
1658
1659 visible_categories_iterator visible_categories_begin() const {
1660 return visible_categories_iterator(getCategoryListRaw());
1661 }
1662
1663
1664 visible_categories_iterator visible_categories_end() const {
1665 return visible_categories_iterator();
1666 }
1667
1668
1669 bool visible_categories_empty() const {
1670 return visible_categories_begin() == visible_categories_end();
1671 }
1672
1673 private:
1674
1675
1676
1677 static bool isKnownCategory(ObjCCategoryDecl *) { return true; }
1678
1679 public:
1680
1681
1682 using known_categories_iterator = filtered_category_iterator<isKnownCategory>;
1683 using known_categories_range =
1684 llvm::iterator_range<known_categories_iterator>;
1685
1686 known_categories_range known_categories() const {
1687 return known_categories_range(known_categories_begin(),
1688 known_categories_end());
1689 }
1690
1691
1692
1693 known_categories_iterator known_categories_begin() const {
1694 return known_categories_iterator(getCategoryListRaw());
1695 }
1696
1697
1698 known_categories_iterator known_categories_end() const {
1699 return known_categories_iterator();
1700 }
1701
1702
1703 bool known_categories_empty() const {
1704 return known_categories_begin() == known_categories_end();
1705 }
1706
1707 private:
1708
1709
1710
1711 static bool isVisibleExtension(ObjCCategoryDecl *Cat);
1712
1713 public:
1714
1715
1716 using visible_extensions_iterator =
1717 filtered_category_iterator<isVisibleExtension>;
1718
1719 using visible_extensions_range =
1720 llvm::iterator_range<visible_extensions_iterator>;
1721
1722 visible_extensions_range visible_extensions() const {
1723 return visible_extensions_range(visible_extensions_begin(),
1724 visible_extensions_end());
1725 }
1726
1727
1728
1729 visible_extensions_iterator visible_extensions_begin() const {
1730 return visible_extensions_iterator(getCategoryListRaw());
1731 }
1732
1733
1734 visible_extensions_iterator visible_extensions_end() const {
1735 return visible_extensions_iterator();
1736 }
1737
1738
1739 bool visible_extensions_empty() const {
1740 return visible_extensions_begin() == visible_extensions_end();
1741 }
1742
1743 private:
1744
1745
1746
1747 static bool isKnownExtension(ObjCCategoryDecl *Cat);
1748
1749 public:
1750 friend class ASTDeclMerger;
1751 friend class ASTDeclReader;
1752 friend class ASTDeclWriter;
1753 friend class ASTReader;
1754
1755
1756 using known_extensions_iterator =
1757 filtered_category_iterator<isKnownExtension>;
1758 using known_extensions_range =
1759 llvm::iterator_range<known_extensions_iterator>;
1760
1761 known_extensions_range known_extensions() const {
1762 return known_extensions_range(known_extensions_begin(),
1763 known_extensions_end());
1764 }
1765
1766
1767
1768 known_extensions_iterator known_extensions_begin() const {
1769 return known_extensions_iterator(getCategoryListRaw());
1770 }
1771
1772
1773 known_extensions_iterator known_extensions_end() const {
1774 return known_extensions_iterator();
1775 }
1776
1777
1778 bool known_extensions_empty() const {
1779 return known_extensions_begin() == known_extensions_end();
1780 }
1781
1782
1783
1784 ObjCCategoryDecl* getCategoryListRaw() const {
1785
1786 if (!hasDefinition())
1787 return nullptr;
1788
1789 if (data().ExternallyCompleted)
1790 LoadExternalDefinition();
1791
1792 return data().CategoryList;
1793 }
1794
1795
1796
1797 void setCategoryListRaw(ObjCCategoryDecl *category) {
1798 data().CategoryList = category;
1799 }
1800
1801 ObjCPropertyDecl *
1802 FindPropertyVisibleInPrimaryClass(const IdentifierInfo *PropertyId,
1803 ObjCPropertyQueryKind QueryKind) const;
1804
1805 void collectPropertiesToImplement(PropertyMap &PM) const override;
1806
1807
1808
1809 bool isSuperClassOf(const ObjCInterfaceDecl *I) const {
1810
1811 while (I != nullptr) {
1812 if (declaresSameEntity(this, I))
1813 return true;
1814
1815 I = I->getSuperClass();
1816 }
1817 return false;
1818 }
1819
1820
1821
1822 bool isArcWeakrefUnavailable() const;
1823
1824
1825
1826
1827 const ObjCInterfaceDecl *isObjCRequiresPropertyDefs() const;
1828
1829 ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName,
1830 ObjCInterfaceDecl *&ClassDeclared);
1831 ObjCIvarDecl *lookupInstanceVariable(IdentifierInfo *IVarName) {
1832 ObjCInterfaceDecl *ClassDeclared;
1833 return lookupInstanceVariable(IVarName, ClassDeclared);
1834 }
1835
1836 ObjCProtocolDecl *lookupNestedProtocol(IdentifierInfo *Name);
1837
1838
1839
1840 ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance,
1841 bool shallowCategoryLookup = false,
1842 bool followSuper = true,
1843 const ObjCCategoryDecl *C = nullptr) const;
1844
1845
1846 ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
1847 return lookupMethod(Sel, true);
1848 }
1849
1850
1851 ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
1852 return lookupMethod(Sel, false);
1853 }
1854
1855 ObjCInterfaceDecl *lookupInheritedClass(const IdentifierInfo *ICName);
1856
1857
1858 ObjCMethodDecl *lookupPrivateMethod(const Selector &Sel,
1859 bool Instance=true) const;
1860
1861 ObjCMethodDecl *lookupPrivateClassMethod(const Selector &Sel) {
1862 return lookupPrivateMethod(Sel, false);
1863 }
1864
1865
1866
1867
1868 ObjCMethodDecl *lookupPropertyAccessor(const Selector Sel,
1869 const ObjCCategoryDecl *Cat,
1870 bool IsClassProperty) const {
1871 return lookupMethod(Sel, !IsClassProperty,
1872 false,
1873 true ,
1874 Cat);
1875 }
1876
1877 SourceLocation getEndOfDefinitionLoc() const {
1878 if (!hasDefinition())
1879 return getLocation();
1880
1881 return data().EndLoc;
1882 }
1883
1884 void setEndOfDefinitionLoc(SourceLocation LE) { data().EndLoc = LE; }
1885
1886
1887 SourceLocation getSuperClassLoc() const;
1888
1889
1890
1891
1892 bool isImplicitInterfaceDecl() const {
1893 return hasDefinition() ? data().Definition->isImplicit() : isImplicit();
1894 }
1895
1896
1897
1898
1899 bool ClassImplementsProtocol(ObjCProtocolDecl *lProto,
1900 bool lookupCategory,
1901 bool RHSIsQualifiedID = false);
1902
1903 using redecl_range = redeclarable_base::redecl_range;
1904 using redecl_iterator = redeclarable_base::redecl_iterator;
1905
1906 using redeclarable_base::redecls_begin;
1907 using redeclarable_base::redecls_end;
1908 using redeclarable_base::redecls;
1909 using redeclarable_base::getPreviousDecl;
1910 using redeclarable_base::getMostRecentDecl;
1911 using redeclarable_base::isFirstDecl;
1912
1913
1914 ObjCInterfaceDecl *getCanonicalDecl() override { return getFirstDecl(); }
1915 const ObjCInterfaceDecl *getCanonicalDecl() const { return getFirstDecl(); }
1916
1917
1918 const Type *getTypeForDecl() const { return TypeForDecl; }
1919 void setTypeForDecl(const Type *TD) const { TypeForDecl = TD; }
1920
1921
1922 unsigned getODRHash();
1923
1924 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1925 static bool classofKind(Kind K) { return K == ObjCInterface; }
1926
1927 private:
1928
1929 bool hasODRHash() const;
1930 void setHasODRHash(bool HasHash);
1931
1932 const ObjCInterfaceDecl *findInterfaceWithDesignatedInitializers() const;
1933 bool inheritsDesignatedInitializers() const;
1934 };
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951 class ObjCIvarDecl : public FieldDecl {
1952 void anchor() override;
1953
1954 public:
1955 enum AccessControl {
1956 None, Private, Protected, Public, Package
1957 };
1958
1959 private:
1960 ObjCIvarDecl(ObjCContainerDecl *DC, SourceLocation StartLoc,
1961 SourceLocation IdLoc, const IdentifierInfo *Id, QualType T,
1962 TypeSourceInfo *TInfo, AccessControl ac, Expr *BW,
1963 bool synthesized)
1964 : FieldDecl(ObjCIvar, DC, StartLoc, IdLoc, Id, T, TInfo, BW,
1965 false, ICIS_NoInit),
1966 DeclAccess(ac), Synthesized(synthesized) {}
1967
1968 public:
1969 static ObjCIvarDecl *Create(ASTContext &C, ObjCContainerDecl *DC,
1970 SourceLocation StartLoc, SourceLocation IdLoc,
1971 const IdentifierInfo *Id, QualType T,
1972 TypeSourceInfo *TInfo, AccessControl ac,
1973 Expr *BW = nullptr, bool synthesized = false);
1974
1975 static ObjCIvarDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
1976
1977
1978
1979
1980
1981 ObjCInterfaceDecl *getContainingInterface();
1982 const ObjCInterfaceDecl *getContainingInterface() const {
1983 return const_cast<ObjCIvarDecl *>(this)->getContainingInterface();
1984 }
1985
1986 ObjCIvarDecl *getNextIvar() { return NextIvar; }
1987 const ObjCIvarDecl *getNextIvar() const { return NextIvar; }
1988 void setNextIvar(ObjCIvarDecl *ivar) { NextIvar = ivar; }
1989
1990 ObjCIvarDecl *getCanonicalDecl() override {
1991 return cast<ObjCIvarDecl>(FieldDecl::getCanonicalDecl());
1992 }
1993 const ObjCIvarDecl *getCanonicalDecl() const {
1994 return const_cast<ObjCIvarDecl *>(this)->getCanonicalDecl();
1995 }
1996
1997 void setAccessControl(AccessControl ac) { DeclAccess = ac; }
1998
1999 AccessControl getAccessControl() const { return AccessControl(DeclAccess); }
2000
2001 AccessControl getCanonicalAccessControl() const {
2002 return DeclAccess == None ? Protected : AccessControl(DeclAccess);
2003 }
2004
2005 void setSynthesize(bool synth) { Synthesized = synth; }
2006 bool getSynthesize() const { return Synthesized; }
2007
2008
2009
2010 QualType getUsageType(QualType objectType) const;
2011
2012
2013 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2014 static bool classofKind(Kind K) { return K == ObjCIvar; }
2015
2016 private:
2017
2018
2019 ObjCIvarDecl *NextIvar = nullptr;
2020
2021
2022 LLVM_PREFERRED_TYPE(AccessControl)
2023 unsigned DeclAccess : 3;
2024 LLVM_PREFERRED_TYPE(bool)
2025 unsigned Synthesized : 1;
2026 };
2027
2028
2029 class ObjCAtDefsFieldDecl : public FieldDecl {
2030 ObjCAtDefsFieldDecl(DeclContext *DC, SourceLocation StartLoc,
2031 SourceLocation IdLoc, IdentifierInfo *Id,
2032 QualType T, Expr *BW)
2033 : FieldDecl(ObjCAtDefsField, DC, StartLoc, IdLoc, Id, T,
2034 nullptr,
2035 BW, false, ICIS_NoInit) {}
2036
2037 void anchor() override;
2038
2039 public:
2040 static ObjCAtDefsFieldDecl *Create(ASTContext &C, DeclContext *DC,
2041 SourceLocation StartLoc,
2042 SourceLocation IdLoc, IdentifierInfo *Id,
2043 QualType T, Expr *BW);
2044
2045 static ObjCAtDefsFieldDecl *CreateDeserialized(ASTContext &C,
2046 GlobalDeclID ID);
2047
2048
2049 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2050 static bool classofKind(Kind K) { return K == ObjCAtDefsField; }
2051 };
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082 class ObjCProtocolDecl : public ObjCContainerDecl,
2083 public Redeclarable<ObjCProtocolDecl> {
2084 struct DefinitionData {
2085
2086 ObjCProtocolDecl *Definition;
2087
2088
2089 ObjCProtocolList ReferencedProtocols;
2090
2091
2092 LLVM_PREFERRED_TYPE(bool)
2093 unsigned HasODRHash : 1;
2094
2095
2096 unsigned ODRHash = 0;
2097 };
2098
2099
2100
2101
2102
2103
2104 llvm::PointerIntPair<DefinitionData *, 1, bool> Data;
2105
2106 ObjCProtocolDecl(ASTContext &C, DeclContext *DC, IdentifierInfo *Id,
2107 SourceLocation nameLoc, SourceLocation atStartLoc,
2108 ObjCProtocolDecl *PrevDecl);
2109
2110 void anchor() override;
2111
2112 DefinitionData &data() const {
2113 assert(Data.getPointer() && "Objective-C protocol has no definition!");
2114 return *Data.getPointer();
2115 }
2116
2117 void allocateDefinitionData();
2118
2119 using redeclarable_base = Redeclarable<ObjCProtocolDecl>;
2120
2121 ObjCProtocolDecl *getNextRedeclarationImpl() override {
2122 return getNextRedeclaration();
2123 }
2124
2125 ObjCProtocolDecl *getPreviousDeclImpl() override {
2126 return getPreviousDecl();
2127 }
2128
2129 ObjCProtocolDecl *getMostRecentDeclImpl() override {
2130 return getMostRecentDecl();
2131 }
2132
2133
2134 bool hasODRHash() const;
2135 void setHasODRHash(bool HasHash);
2136
2137 public:
2138 friend class ASTDeclMerger;
2139 friend class ASTDeclReader;
2140 friend class ASTDeclWriter;
2141 friend class ASTReader;
2142 friend class ODRDiagsEmitter;
2143
2144 static ObjCProtocolDecl *Create(ASTContext &C, DeclContext *DC,
2145 IdentifierInfo *Id,
2146 SourceLocation nameLoc,
2147 SourceLocation atStartLoc,
2148 ObjCProtocolDecl *PrevDecl);
2149
2150 static ObjCProtocolDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
2151
2152 const ObjCProtocolList &getReferencedProtocols() const {
2153 assert(hasDefinition() && "No definition available!");
2154 return data().ReferencedProtocols;
2155 }
2156
2157 using protocol_iterator = ObjCProtocolList::iterator;
2158 using protocol_range = llvm::iterator_range<protocol_iterator>;
2159
2160 protocol_range protocols() const {
2161 return protocol_range(protocol_begin(), protocol_end());
2162 }
2163
2164 protocol_iterator protocol_begin() const {
2165 if (!hasDefinition())
2166 return protocol_iterator();
2167
2168 return data().ReferencedProtocols.begin();
2169 }
2170
2171 protocol_iterator protocol_end() const {
2172 if (!hasDefinition())
2173 return protocol_iterator();
2174
2175 return data().ReferencedProtocols.end();
2176 }
2177
2178 using protocol_loc_iterator = ObjCProtocolList::loc_iterator;
2179 using protocol_loc_range = llvm::iterator_range<protocol_loc_iterator>;
2180
2181 protocol_loc_range protocol_locs() const {
2182 return protocol_loc_range(protocol_loc_begin(), protocol_loc_end());
2183 }
2184
2185 protocol_loc_iterator protocol_loc_begin() const {
2186 if (!hasDefinition())
2187 return protocol_loc_iterator();
2188
2189 return data().ReferencedProtocols.loc_begin();
2190 }
2191
2192 protocol_loc_iterator protocol_loc_end() const {
2193 if (!hasDefinition())
2194 return protocol_loc_iterator();
2195
2196 return data().ReferencedProtocols.loc_end();
2197 }
2198
2199 unsigned protocol_size() const {
2200 if (!hasDefinition())
2201 return 0;
2202
2203 return data().ReferencedProtocols.size();
2204 }
2205
2206
2207
2208 void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
2209 const SourceLocation *Locs, ASTContext &C) {
2210 assert(hasDefinition() && "Protocol is not defined");
2211 data().ReferencedProtocols.set(List, Num, Locs, C);
2212 }
2213
2214
2215
2216 bool isNonRuntimeProtocol() const;
2217
2218
2219
2220 void getImpliedProtocols(llvm::DenseSet<const ObjCProtocolDecl *> &IPs) const;
2221
2222 ObjCProtocolDecl *lookupProtocolNamed(IdentifierInfo *PName);
2223
2224
2225
2226 ObjCMethodDecl *lookupMethod(Selector Sel, bool isInstance) const;
2227
2228 ObjCMethodDecl *lookupInstanceMethod(Selector Sel) const {
2229 return lookupMethod(Sel, true);
2230 }
2231
2232 ObjCMethodDecl *lookupClassMethod(Selector Sel) const {
2233 return lookupMethod(Sel, false);
2234 }
2235
2236
2237 bool hasDefinition() const {
2238
2239
2240
2241
2242 if (!Data.getOpaqueValue())
2243 getMostRecentDecl();
2244
2245 return Data.getPointer();
2246 }
2247
2248
2249 ObjCProtocolDecl *getDefinition() {
2250 return hasDefinition()? Data.getPointer()->Definition : nullptr;
2251 }
2252
2253
2254 const ObjCProtocolDecl *getDefinition() const {
2255 return hasDefinition()? Data.getPointer()->Definition : nullptr;
2256 }
2257
2258
2259
2260 bool isThisDeclarationADefinition() const {
2261 return getDefinition() == this;
2262 }
2263
2264
2265 void startDefinition();
2266
2267
2268
2269
2270
2271 void startDuplicateDefinitionForComparison();
2272 void mergeDuplicateDefinitionWithCommon(const ObjCProtocolDecl *Definition);
2273
2274
2275
2276 StringRef getObjCRuntimeNameAsString() const;
2277
2278 SourceRange getSourceRange() const override LLVM_READONLY {
2279 if (isThisDeclarationADefinition())
2280 return ObjCContainerDecl::getSourceRange();
2281
2282 return SourceRange(getAtStartLoc(), getLocation());
2283 }
2284
2285 using redecl_range = redeclarable_base::redecl_range;
2286 using redecl_iterator = redeclarable_base::redecl_iterator;
2287
2288 using redeclarable_base::redecls_begin;
2289 using redeclarable_base::redecls_end;
2290 using redeclarable_base::redecls;
2291 using redeclarable_base::getPreviousDecl;
2292 using redeclarable_base::getMostRecentDecl;
2293 using redeclarable_base::isFirstDecl;
2294
2295
2296 ObjCProtocolDecl *getCanonicalDecl() override { return getFirstDecl(); }
2297 const ObjCProtocolDecl *getCanonicalDecl() const { return getFirstDecl(); }
2298
2299 void collectPropertiesToImplement(PropertyMap &PM) const override;
2300
2301 void collectInheritedProtocolProperties(const ObjCPropertyDecl *Property,
2302 ProtocolPropertySet &PS,
2303 PropertyDeclOrder &PO) const;
2304
2305
2306 unsigned getODRHash();
2307
2308 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2309 static bool classofKind(Kind K) { return K == ObjCProtocol; }
2310 };
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328 class ObjCCategoryDecl : public ObjCContainerDecl {
2329
2330 ObjCInterfaceDecl *ClassInterface;
2331
2332
2333 ObjCTypeParamList *TypeParamList = nullptr;
2334
2335
2336 ObjCProtocolList ReferencedProtocols;
2337
2338
2339
2340 ObjCCategoryDecl *NextClassCategory = nullptr;
2341
2342
2343 SourceLocation CategoryNameLoc;
2344
2345
2346 SourceLocation IvarLBraceLoc;
2347 SourceLocation IvarRBraceLoc;
2348
2349 ObjCCategoryDecl(DeclContext *DC, SourceLocation AtLoc,
2350 SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc,
2351 const IdentifierInfo *Id, ObjCInterfaceDecl *IDecl,
2352 ObjCTypeParamList *typeParamList,
2353 SourceLocation IvarLBraceLoc = SourceLocation(),
2354 SourceLocation IvarRBraceLoc = SourceLocation());
2355
2356 void anchor() override;
2357
2358 public:
2359 friend class ASTDeclReader;
2360 friend class ASTDeclWriter;
2361
2362 static ObjCCategoryDecl *
2363 Create(ASTContext &C, DeclContext *DC, SourceLocation AtLoc,
2364 SourceLocation ClassNameLoc, SourceLocation CategoryNameLoc,
2365 const IdentifierInfo *Id, ObjCInterfaceDecl *IDecl,
2366 ObjCTypeParamList *typeParamList,
2367 SourceLocation IvarLBraceLoc = SourceLocation(),
2368 SourceLocation IvarRBraceLoc = SourceLocation());
2369 static ObjCCategoryDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
2370
2371 ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
2372 const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
2373
2374
2375
2376 ObjCTypeParamList *getTypeParamList() const { return TypeParamList; }
2377
2378
2379
2380
2381
2382 void setTypeParamList(ObjCTypeParamList *TPL);
2383
2384
2385 ObjCCategoryImplDecl *getImplementation() const;
2386 void setImplementation(ObjCCategoryImplDecl *ImplD);
2387
2388
2389
2390 void setProtocolList(ObjCProtocolDecl *const*List, unsigned Num,
2391 const SourceLocation *Locs, ASTContext &C) {
2392 ReferencedProtocols.set(List, Num, Locs, C);
2393 }
2394
2395 const ObjCProtocolList &getReferencedProtocols() const {
2396 return ReferencedProtocols;
2397 }
2398
2399 using protocol_iterator = ObjCProtocolList::iterator;
2400 using protocol_range = llvm::iterator_range<protocol_iterator>;
2401
2402 protocol_range protocols() const {
2403 return protocol_range(protocol_begin(), protocol_end());
2404 }
2405
2406 protocol_iterator protocol_begin() const {
2407 return ReferencedProtocols.begin();
2408 }
2409
2410 protocol_iterator protocol_end() const { return ReferencedProtocols.end(); }
2411 unsigned protocol_size() const { return ReferencedProtocols.size(); }
2412
2413 using protocol_loc_iterator = ObjCProtocolList::loc_iterator;
2414 using protocol_loc_range = llvm::iterator_range<protocol_loc_iterator>;
2415
2416 protocol_loc_range protocol_locs() const {
2417 return protocol_loc_range(protocol_loc_begin(), protocol_loc_end());
2418 }
2419
2420 protocol_loc_iterator protocol_loc_begin() const {
2421 return ReferencedProtocols.loc_begin();
2422 }
2423
2424 protocol_loc_iterator protocol_loc_end() const {
2425 return ReferencedProtocols.loc_end();
2426 }
2427
2428 ObjCCategoryDecl *getNextClassCategory() const { return NextClassCategory; }
2429
2430
2431
2432 ObjCCategoryDecl *getNextClassCategoryRaw() const {
2433 return NextClassCategory;
2434 }
2435
2436 bool IsClassExtension() const { return getIdentifier() == nullptr; }
2437
2438 using ivar_iterator = specific_decl_iterator<ObjCIvarDecl>;
2439 using ivar_range = llvm::iterator_range<specific_decl_iterator<ObjCIvarDecl>>;
2440
2441 ivar_range ivars() const { return ivar_range(ivar_begin(), ivar_end()); }
2442
2443 ivar_iterator ivar_begin() const {
2444 return ivar_iterator(decls_begin());
2445 }
2446
2447 ivar_iterator ivar_end() const {
2448 return ivar_iterator(decls_end());
2449 }
2450
2451 unsigned ivar_size() const {
2452 return std::distance(ivar_begin(), ivar_end());
2453 }
2454
2455 bool ivar_empty() const {
2456 return ivar_begin() == ivar_end();
2457 }
2458
2459 SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
2460 void setCategoryNameLoc(SourceLocation Loc) { CategoryNameLoc = Loc; }
2461
2462 void setIvarLBraceLoc(SourceLocation Loc) { IvarLBraceLoc = Loc; }
2463 SourceLocation getIvarLBraceLoc() const { return IvarLBraceLoc; }
2464 void setIvarRBraceLoc(SourceLocation Loc) { IvarRBraceLoc = Loc; }
2465 SourceLocation getIvarRBraceLoc() const { return IvarRBraceLoc; }
2466
2467 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2468 static bool classofKind(Kind K) { return K == ObjCCategory; }
2469 };
2470
2471 class ObjCImplDecl : public ObjCContainerDecl {
2472
2473 ObjCInterfaceDecl *ClassInterface;
2474
2475 void anchor() override;
2476
2477 protected:
2478 ObjCImplDecl(Kind DK, DeclContext *DC, ObjCInterfaceDecl *classInterface,
2479 const IdentifierInfo *Id, SourceLocation nameLoc,
2480 SourceLocation atStartLoc)
2481 : ObjCContainerDecl(DK, DC, Id, nameLoc, atStartLoc),
2482 ClassInterface(classInterface) {}
2483
2484 public:
2485 const ObjCInterfaceDecl *getClassInterface() const { return ClassInterface; }
2486 ObjCInterfaceDecl *getClassInterface() { return ClassInterface; }
2487 void setClassInterface(ObjCInterfaceDecl *IFace);
2488
2489 void addInstanceMethod(ObjCMethodDecl *method) {
2490
2491 method->setLexicalDeclContext(this);
2492 addDecl(method);
2493 }
2494
2495 void addClassMethod(ObjCMethodDecl *method) {
2496
2497 method->setLexicalDeclContext(this);
2498 addDecl(method);
2499 }
2500
2501 void addPropertyImplementation(ObjCPropertyImplDecl *property);
2502
2503 ObjCPropertyImplDecl *FindPropertyImplDecl(IdentifierInfo *propertyId,
2504 ObjCPropertyQueryKind queryKind) const;
2505 ObjCPropertyImplDecl *FindPropertyImplIvarDecl(IdentifierInfo *ivarId) const;
2506
2507
2508 using propimpl_iterator = specific_decl_iterator<ObjCPropertyImplDecl>;
2509 using propimpl_range =
2510 llvm::iterator_range<specific_decl_iterator<ObjCPropertyImplDecl>>;
2511
2512 propimpl_range property_impls() const {
2513 return propimpl_range(propimpl_begin(), propimpl_end());
2514 }
2515
2516 propimpl_iterator propimpl_begin() const {
2517 return propimpl_iterator(decls_begin());
2518 }
2519
2520 propimpl_iterator propimpl_end() const {
2521 return propimpl_iterator(decls_end());
2522 }
2523
2524 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2525
2526 static bool classofKind(Kind K) {
2527 return K >= firstObjCImpl && K <= lastObjCImpl;
2528 }
2529 };
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544 class ObjCCategoryImplDecl : public ObjCImplDecl {
2545
2546 SourceLocation CategoryNameLoc;
2547
2548 ObjCCategoryImplDecl(DeclContext *DC, const IdentifierInfo *Id,
2549 ObjCInterfaceDecl *classInterface,
2550 SourceLocation nameLoc, SourceLocation atStartLoc,
2551 SourceLocation CategoryNameLoc)
2552 : ObjCImplDecl(ObjCCategoryImpl, DC, classInterface, Id, nameLoc,
2553 atStartLoc),
2554 CategoryNameLoc(CategoryNameLoc) {}
2555
2556 void anchor() override;
2557
2558 public:
2559 friend class ASTDeclReader;
2560 friend class ASTDeclWriter;
2561
2562 static ObjCCategoryImplDecl *
2563 Create(ASTContext &C, DeclContext *DC, const IdentifierInfo *Id,
2564 ObjCInterfaceDecl *classInterface, SourceLocation nameLoc,
2565 SourceLocation atStartLoc, SourceLocation CategoryNameLoc);
2566 static ObjCCategoryImplDecl *CreateDeserialized(ASTContext &C,
2567 GlobalDeclID ID);
2568
2569 ObjCCategoryDecl *getCategoryDecl() const;
2570
2571 SourceLocation getCategoryNameLoc() const { return CategoryNameLoc; }
2572
2573 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2574 static bool classofKind(Kind K) { return K == ObjCCategoryImpl;}
2575 };
2576
2577 raw_ostream &operator<<(raw_ostream &OS, const ObjCCategoryImplDecl &CID);
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596 class ObjCImplementationDecl : public ObjCImplDecl {
2597
2598 ObjCInterfaceDecl *SuperClass;
2599 SourceLocation SuperLoc;
2600
2601
2602 SourceLocation IvarLBraceLoc;
2603 SourceLocation IvarRBraceLoc;
2604
2605
2606
2607 LazyCXXCtorInitializersPtr IvarInitializers;
2608 unsigned NumIvarInitializers = 0;
2609
2610
2611
2612 LLVM_PREFERRED_TYPE(bool)
2613 bool HasNonZeroConstructors : 1;
2614
2615
2616 LLVM_PREFERRED_TYPE(bool)
2617 bool HasDestructors : 1;
2618
2619 ObjCImplementationDecl(DeclContext *DC,
2620 ObjCInterfaceDecl *classInterface,
2621 ObjCInterfaceDecl *superDecl,
2622 SourceLocation nameLoc, SourceLocation atStartLoc,
2623 SourceLocation superLoc = SourceLocation(),
2624 SourceLocation IvarLBraceLoc=SourceLocation(),
2625 SourceLocation IvarRBraceLoc=SourceLocation())
2626 : ObjCImplDecl(ObjCImplementation, DC, classInterface,
2627 classInterface ? classInterface->getIdentifier()
2628 : nullptr,
2629 nameLoc, atStartLoc),
2630 SuperClass(superDecl), SuperLoc(superLoc),
2631 IvarLBraceLoc(IvarLBraceLoc), IvarRBraceLoc(IvarRBraceLoc),
2632 HasNonZeroConstructors(false), HasDestructors(false) {}
2633
2634 void anchor() override;
2635
2636 public:
2637 friend class ASTDeclReader;
2638 friend class ASTDeclWriter;
2639
2640 static ObjCImplementationDecl *Create(ASTContext &C, DeclContext *DC,
2641 ObjCInterfaceDecl *classInterface,
2642 ObjCInterfaceDecl *superDecl,
2643 SourceLocation nameLoc,
2644 SourceLocation atStartLoc,
2645 SourceLocation superLoc = SourceLocation(),
2646 SourceLocation IvarLBraceLoc=SourceLocation(),
2647 SourceLocation IvarRBraceLoc=SourceLocation());
2648
2649 static ObjCImplementationDecl *CreateDeserialized(ASTContext &C,
2650 GlobalDeclID ID);
2651
2652
2653 using init_iterator = CXXCtorInitializer **;
2654
2655
2656 using init_const_iterator = CXXCtorInitializer * const *;
2657
2658 using init_range = llvm::iterator_range<init_iterator>;
2659 using init_const_range = llvm::iterator_range<init_const_iterator>;
2660
2661 init_range inits() { return init_range(init_begin(), init_end()); }
2662
2663 init_const_range inits() const {
2664 return init_const_range(init_begin(), init_end());
2665 }
2666
2667
2668 init_iterator init_begin() {
2669 const auto *ConstThis = this;
2670 return const_cast<init_iterator>(ConstThis->init_begin());
2671 }
2672
2673
2674 init_const_iterator init_begin() const;
2675
2676
2677 init_iterator init_end() {
2678 return init_begin() + NumIvarInitializers;
2679 }
2680
2681
2682 init_const_iterator init_end() const {
2683 return init_begin() + NumIvarInitializers;
2684 }
2685
2686
2687 unsigned getNumIvarInitializers() const {
2688 return NumIvarInitializers;
2689 }
2690
2691 void setNumIvarInitializers(unsigned numNumIvarInitializers) {
2692 NumIvarInitializers = numNumIvarInitializers;
2693 }
2694
2695 void setIvarInitializers(ASTContext &C,
2696 CXXCtorInitializer ** initializers,
2697 unsigned numInitializers);
2698
2699
2700
2701 bool hasNonZeroConstructors() const { return HasNonZeroConstructors; }
2702 void setHasNonZeroConstructors(bool val) { HasNonZeroConstructors = val; }
2703
2704
2705
2706 bool hasDestructors() const { return HasDestructors; }
2707 void setHasDestructors(bool val) { HasDestructors = val; }
2708
2709
2710
2711 IdentifierInfo *getIdentifier() const {
2712 return getClassInterface()->getIdentifier();
2713 }
2714
2715
2716
2717
2718
2719
2720 StringRef getName() const {
2721 assert(getIdentifier() && "Name is not a simple identifier");
2722 return getIdentifier()->getName();
2723 }
2724
2725
2726
2727
2728 std::string getNameAsString() const { return std::string(getName()); }
2729
2730
2731
2732 StringRef getObjCRuntimeNameAsString() const;
2733
2734 const ObjCInterfaceDecl *getSuperClass() const { return SuperClass; }
2735 ObjCInterfaceDecl *getSuperClass() { return SuperClass; }
2736 SourceLocation getSuperClassLoc() const { return SuperLoc; }
2737
2738 void setSuperClass(ObjCInterfaceDecl * superCls) { SuperClass = superCls; }
2739
2740 void setIvarLBraceLoc(SourceLocation Loc) { IvarLBraceLoc = Loc; }
2741 SourceLocation getIvarLBraceLoc() const { return IvarLBraceLoc; }
2742 void setIvarRBraceLoc(SourceLocation Loc) { IvarRBraceLoc = Loc; }
2743 SourceLocation getIvarRBraceLoc() const { return IvarRBraceLoc; }
2744
2745 using ivar_iterator = specific_decl_iterator<ObjCIvarDecl>;
2746 using ivar_range = llvm::iterator_range<specific_decl_iterator<ObjCIvarDecl>>;
2747
2748 ivar_range ivars() const { return ivar_range(ivar_begin(), ivar_end()); }
2749
2750 ivar_iterator ivar_begin() const {
2751 return ivar_iterator(decls_begin());
2752 }
2753
2754 ivar_iterator ivar_end() const {
2755 return ivar_iterator(decls_end());
2756 }
2757
2758 unsigned ivar_size() const {
2759 return std::distance(ivar_begin(), ivar_end());
2760 }
2761
2762 bool ivar_empty() const {
2763 return ivar_begin() == ivar_end();
2764 }
2765
2766 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2767 static bool classofKind(Kind K) { return K == ObjCImplementation; }
2768 };
2769
2770 raw_ostream &operator<<(raw_ostream &OS, const ObjCImplementationDecl &ID);
2771
2772
2773
2774 class ObjCCompatibleAliasDecl : public NamedDecl {
2775
2776 ObjCInterfaceDecl *AliasedClass;
2777
2778 ObjCCompatibleAliasDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *Id,
2779 ObjCInterfaceDecl* aliasedClass)
2780 : NamedDecl(ObjCCompatibleAlias, DC, L, Id), AliasedClass(aliasedClass) {}
2781
2782 void anchor() override;
2783
2784 public:
2785 static ObjCCompatibleAliasDecl *Create(ASTContext &C, DeclContext *DC,
2786 SourceLocation L, IdentifierInfo *Id,
2787 ObjCInterfaceDecl* aliasedClass);
2788
2789 static ObjCCompatibleAliasDecl *CreateDeserialized(ASTContext &C,
2790 GlobalDeclID ID);
2791
2792 const ObjCInterfaceDecl *getClassInterface() const { return AliasedClass; }
2793 ObjCInterfaceDecl *getClassInterface() { return AliasedClass; }
2794 void setClassInterface(ObjCInterfaceDecl *D) { AliasedClass = D; }
2795
2796 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2797 static bool classofKind(Kind K) { return K == ObjCCompatibleAlias; }
2798 };
2799
2800
2801
2802
2803
2804 class ObjCPropertyImplDecl : public Decl {
2805 public:
2806 enum Kind {
2807 Synthesize,
2808 Dynamic
2809 };
2810
2811 private:
2812 SourceLocation AtLoc;
2813
2814
2815
2816
2817
2818
2819
2820 SourceLocation IvarLoc;
2821
2822
2823 ObjCPropertyDecl *PropertyDecl;
2824
2825
2826 ObjCIvarDecl *PropertyIvarDecl;
2827
2828
2829 ObjCMethodDecl *GetterMethodDecl = nullptr;
2830
2831 ObjCMethodDecl *SetterMethodDecl = nullptr;
2832
2833
2834
2835 Expr *GetterCXXConstructor = nullptr;
2836
2837
2838
2839 Expr *SetterCXXAssignment = nullptr;
2840
2841 ObjCPropertyImplDecl(DeclContext *DC, SourceLocation atLoc, SourceLocation L,
2842 ObjCPropertyDecl *property,
2843 Kind PK,
2844 ObjCIvarDecl *ivarDecl,
2845 SourceLocation ivarLoc)
2846 : Decl(ObjCPropertyImpl, DC, L), AtLoc(atLoc),
2847 IvarLoc(ivarLoc), PropertyDecl(property), PropertyIvarDecl(ivarDecl) {
2848 assert(PK == Dynamic || PropertyIvarDecl);
2849 }
2850
2851 public:
2852 friend class ASTDeclReader;
2853
2854 static ObjCPropertyImplDecl *Create(ASTContext &C, DeclContext *DC,
2855 SourceLocation atLoc, SourceLocation L,
2856 ObjCPropertyDecl *property,
2857 Kind PK,
2858 ObjCIvarDecl *ivarDecl,
2859 SourceLocation ivarLoc);
2860
2861 static ObjCPropertyImplDecl *CreateDeserialized(ASTContext &C,
2862 GlobalDeclID ID);
2863
2864 SourceRange getSourceRange() const override LLVM_READONLY;
2865
2866 SourceLocation getBeginLoc() const LLVM_READONLY { return AtLoc; }
2867 void setAtLoc(SourceLocation Loc) { AtLoc = Loc; }
2868
2869 ObjCPropertyDecl *getPropertyDecl() const {
2870 return PropertyDecl;
2871 }
2872 void setPropertyDecl(ObjCPropertyDecl *Prop) { PropertyDecl = Prop; }
2873
2874 Kind getPropertyImplementation() const {
2875 return PropertyIvarDecl ? Synthesize : Dynamic;
2876 }
2877
2878 ObjCIvarDecl *getPropertyIvarDecl() const {
2879 return PropertyIvarDecl;
2880 }
2881 SourceLocation getPropertyIvarDeclLoc() const { return IvarLoc; }
2882
2883 void setPropertyIvarDecl(ObjCIvarDecl *Ivar,
2884 SourceLocation IvarLoc) {
2885 PropertyIvarDecl = Ivar;
2886 this->IvarLoc = IvarLoc;
2887 }
2888
2889
2890
2891
2892
2893
2894
2895
2896 bool isIvarNameSpecified() const {
2897 return IvarLoc.isValid() && IvarLoc != getLocation();
2898 }
2899
2900 ObjCMethodDecl *getGetterMethodDecl() const { return GetterMethodDecl; }
2901 void setGetterMethodDecl(ObjCMethodDecl *MD) { GetterMethodDecl = MD; }
2902
2903 ObjCMethodDecl *getSetterMethodDecl() const { return SetterMethodDecl; }
2904 void setSetterMethodDecl(ObjCMethodDecl *MD) { SetterMethodDecl = MD; }
2905
2906 Expr *getGetterCXXConstructor() const {
2907 return GetterCXXConstructor;
2908 }
2909
2910 void setGetterCXXConstructor(Expr *getterCXXConstructor) {
2911 GetterCXXConstructor = getterCXXConstructor;
2912 }
2913
2914 Expr *getSetterCXXAssignment() const {
2915 return SetterCXXAssignment;
2916 }
2917
2918 void setSetterCXXAssignment(Expr *setterCXXAssignment) {
2919 SetterCXXAssignment = setterCXXAssignment;
2920 }
2921
2922 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2923 static bool classofKind(Decl::Kind K) { return K == ObjCPropertyImpl; }
2924 };
2925
2926 template<bool (*Filter)(ObjCCategoryDecl *)>
2927 void
2928 ObjCInterfaceDecl::filtered_category_iterator<Filter>::
2929 findAcceptableCategory() {
2930 while (Current && !Filter(Current))
2931 Current = Current->getNextClassCategoryRaw();
2932 }
2933
2934 template<bool (*Filter)(ObjCCategoryDecl *)>
2935 inline ObjCInterfaceDecl::filtered_category_iterator<Filter> &
2936 ObjCInterfaceDecl::filtered_category_iterator<Filter>::operator++() {
2937 Current = Current->getNextClassCategoryRaw();
2938 findAcceptableCategory();
2939 return *this;
2940 }
2941
2942 inline bool ObjCInterfaceDecl::isVisibleCategory(ObjCCategoryDecl *Cat) {
2943 return !Cat->isInvalidDecl() && Cat->isUnconditionallyVisible();
2944 }
2945
2946 inline bool ObjCInterfaceDecl::isVisibleExtension(ObjCCategoryDecl *Cat) {
2947 return !Cat->isInvalidDecl() && Cat->IsClassExtension() &&
2948 Cat->isUnconditionallyVisible();
2949 }
2950
2951 inline bool ObjCInterfaceDecl::isKnownExtension(ObjCCategoryDecl *Cat) {
2952 return !Cat->isInvalidDecl() && Cat->IsClassExtension();
2953 }
2954
2955 }
2956
2957 #endif