enum ImplementationControl { None, Required, Optional };
private:
- // The conventional meaning of this method; an ObjCMethodFamily.
- // This is not serialized; instead, it is computed on demand and
- // cached.
- mutable unsigned Family : ObjCMethodFamilyBitWidth;
-
- /// instance (true) or class (false) method.
- unsigned IsInstance : 1;
- unsigned IsVariadic : 1;
-
- /// True if this method is the getter or setter for an explicit property.
- unsigned IsPropertyAccessor : 1;
-
- // Method has a definition.
- unsigned IsDefined : 1;
-
- /// Method redeclaration in the same interface.
- unsigned IsRedeclaration : 1;
-
- /// Is redeclared in the same interface.
- mutable unsigned HasRedeclaration : 1;
-
- // NOTE: VC++ treats enums as signed, avoid using ImplementationControl enum
- /// \@required/\@optional
- unsigned DeclImplementation : 2;
-
- // NOTE: VC++ treats enums as signed, avoid using the ObjCDeclQualifier enum
- /// in, inout, etc.
- unsigned objcDeclQualifier : 7;
-
- /// Indicates whether this method has a related result type.
- unsigned RelatedResultType : 1;
-
- /// Whether the locations of the selector identifiers are in a
- /// "standard" position, a enum SelectorLocationsKind.
- unsigned SelLocsKind : 2;
-
- /// Whether this method overrides any other in the class hierarchy.
- ///
- /// A method is said to override any method in the class's
- /// base classes, its protocols, or its categories' protocols, that has
- /// the same selector and is of the same kind (class or instance).
- /// A method in an implementation is not considered as overriding the same
- /// method in the interface or its categories.
- unsigned IsOverriding : 1;
-
- /// Indicates if the method was a definition but its body was skipped.
- unsigned HasSkippedBody : 1;
-
- // Return type of this method.
+ /// Return type of this method.
QualType MethodDeclType;
- // Type source information for the return type.
+ /// Type source information for the return type.
TypeSourceInfo *ReturnTInfo;
/// Array of ParmVarDecls for the formal parameters of this method
/// List of attributes for this method declaration.
SourceLocation DeclEndLoc; // the location of the ';' or '{'.
- // The following are only used for method definitions, null otherwise.
+ /// The following are only used for method definitions, null otherwise.
LazyDeclStmtPtr Body;
/// SelfDecl - Decl for the implicit self parameter. This is lazily
bool isVariadic = false, bool isPropertyAccessor = false,
bool isImplicitlyDeclared = false, bool isDefined = false,
ImplementationControl impControl = None,
- bool HasRelatedResultType = false)
- : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo),
- DeclContext(ObjCMethod), Family(InvalidObjCMethodFamily),
- IsInstance(isInstance), IsVariadic(isVariadic),
- IsPropertyAccessor(isPropertyAccessor), IsDefined(isDefined),
- IsRedeclaration(0), HasRedeclaration(0), DeclImplementation(impControl),
- objcDeclQualifier(OBJC_TQ_None),
- RelatedResultType(HasRelatedResultType),
- SelLocsKind(SelLoc_StandardNoSpace), IsOverriding(0), HasSkippedBody(0),
- MethodDeclType(T), ReturnTInfo(ReturnTInfo), DeclEndLoc(endLoc) {
- setImplicit(isImplicitlyDeclared);
- }
+ bool HasRelatedResultType = false);
SelectorLocationsKind getSelLocsKind() const {
- return (SelectorLocationsKind)SelLocsKind;
+ return static_cast<SelectorLocationsKind>(ObjCMethodDeclBits.SelLocsKind);
+ }
+
+ void setSelLocsKind(SelectorLocationsKind Kind) {
+ ObjCMethodDeclBits.SelLocsKind = Kind;
}
bool hasStandardSelLocs() const {
/// Get a pointer to the stored selector identifiers locations array.
/// No locations will be stored if HasStandardSelLocs is true.
SourceLocation *getStoredSelLocs() {
- return reinterpret_cast<SourceLocation*>(getParams() + NumParams);
+ return reinterpret_cast<SourceLocation *>(getParams() + NumParams);
}
const SourceLocation *getStoredSelLocs() const {
- return reinterpret_cast<const SourceLocation*>(getParams() + NumParams);
+ return reinterpret_cast<const SourceLocation *>(getParams() + NumParams);
}
/// Get a pointer to the stored selector identifiers locations array.
}
ObjCDeclQualifier getObjCDeclQualifier() const {
- return ObjCDeclQualifier(objcDeclQualifier);
+ return static_cast<ObjCDeclQualifier>(ObjCMethodDeclBits.objcDeclQualifier);
+ }
+
+ void setObjCDeclQualifier(ObjCDeclQualifier QV) {
+ ObjCMethodDeclBits.objcDeclQualifier = QV;
}
- void setObjCDeclQualifier(ObjCDeclQualifier QV) { objcDeclQualifier = QV; }
/// Determine whether this method has a result type that is related
/// to the message receiver's type.
- bool hasRelatedResultType() const { return RelatedResultType; }
+ bool hasRelatedResultType() const {
+ return ObjCMethodDeclBits.RelatedResultType;
+ }
/// Note whether this method has a related result type.
- void SetRelatedResultType(bool RRT = true) { RelatedResultType = RRT; }
+ void setRelatedResultType(bool RRT = true) {
+ ObjCMethodDeclBits.RelatedResultType = RRT;
+ }
/// True if this is a method redeclaration in the same interface.
- bool isRedeclaration() const { return IsRedeclaration; }
+ bool isRedeclaration() const { return ObjCMethodDeclBits.IsRedeclaration; }
+ void setIsRedeclaration(bool RD) { ObjCMethodDeclBits.IsRedeclaration = RD; }
void setAsRedeclaration(const ObjCMethodDecl *PrevMethod);
+ /// True if redeclared in the same interface.
+ bool hasRedeclaration() const { return ObjCMethodDeclBits.HasRedeclaration; }
+ void setHasRedeclaration(bool HRD) const {
+ ObjCMethodDeclBits.HasRedeclaration = HRD;
+ }
+
/// Returns the location where the declarator ends. It will be
/// the location of ';' for a method declaration and the location of '{'
/// for a method definition.
/// Determines the family of this method.
ObjCMethodFamily getMethodFamily() const;
- bool isInstanceMethod() const { return IsInstance; }
- void setInstanceMethod(bool isInst) { IsInstance = isInst; }
- bool isVariadic() const { return IsVariadic; }
- void setVariadic(bool isVar) { IsVariadic = isVar; }
+ bool isInstanceMethod() const { return ObjCMethodDeclBits.IsInstance; }
+ void setInstanceMethod(bool isInst) {
+ ObjCMethodDeclBits.IsInstance = isInst;
+ }
- bool isClassMethod() const { return !IsInstance; }
+ bool isVariadic() const { return ObjCMethodDeclBits.IsVariadic; }
+ void setVariadic(bool isVar) { ObjCMethodDeclBits.IsVariadic = isVar; }
- bool isPropertyAccessor() const { return IsPropertyAccessor; }
- void setPropertyAccessor(bool isAccessor) { IsPropertyAccessor = isAccessor; }
+ bool isClassMethod() const { return !isInstanceMethod(); }
- bool isDefined() const { return IsDefined; }
- void setDefined(bool isDefined) { IsDefined = isDefined; }
+ bool isPropertyAccessor() const {
+ return ObjCMethodDeclBits.IsPropertyAccessor;
+ }
+
+ void setPropertyAccessor(bool isAccessor) {
+ ObjCMethodDeclBits.IsPropertyAccessor = isAccessor;
+ }
+
+ bool isDefined() const { return ObjCMethodDeclBits.IsDefined; }
+ void setDefined(bool isDefined) { ObjCMethodDeclBits.IsDefined = isDefined; }
/// Whether this method overrides any other in the class hierarchy.
///
/// the same selector and is of the same kind (class or instance).
/// A method in an implementation is not considered as overriding the same
/// method in the interface or its categories.
- bool isOverriding() const { return IsOverriding; }
- void setOverriding(bool isOverriding) { IsOverriding = isOverriding; }
+ bool isOverriding() const { return ObjCMethodDeclBits.IsOverriding; }
+ void setOverriding(bool IsOver) { ObjCMethodDeclBits.IsOverriding = IsOver; }
/// Return overridden methods for the given \p Method.
///
SmallVectorImpl<const ObjCMethodDecl *> &Overridden) const;
/// True if the method was a definition but its body was skipped.
- bool hasSkippedBody() const { return HasSkippedBody; }
- void setHasSkippedBody(bool Skipped = true) { HasSkippedBody = Skipped; }
+ bool hasSkippedBody() const { return ObjCMethodDeclBits.HasSkippedBody; }
+ void setHasSkippedBody(bool Skipped = true) {
+ ObjCMethodDeclBits.HasSkippedBody = Skipped;
+ }
/// Returns the property associated with this method's selector.
///
// Related to protocols declared in \@protocol
void setDeclImplementation(ImplementationControl ic) {
- DeclImplementation = ic;
+ ObjCMethodDeclBits.DeclImplementation = ic;
}
ImplementationControl getImplementationControl() const {
- return ImplementationControl(DeclImplementation);
+ return ImplementationControl(ObjCMethodDeclBits.DeclImplementation);
}
bool isOptional() const {
/// ObjCProtocolDecl, and ObjCImplDecl.
///
class ObjCContainerDecl : public NamedDecl, public DeclContext {
- SourceLocation AtStart;
-
// These two locations in the range mark the end of the method container.
// The first points to the '@' token, and the second to the 'end' token.
SourceRange AtEnd;
void anchor() override;
public:
- ObjCContainerDecl(Kind DK, DeclContext *DC,
- IdentifierInfo *Id, SourceLocation nameLoc,
- SourceLocation atStartLoc)
- : NamedDecl(DK, DC, nameLoc, Id), DeclContext(DK), AtStart(atStartLoc) {}
+ ObjCContainerDecl(Kind DK, DeclContext *DC, IdentifierInfo *Id,
+ SourceLocation nameLoc, SourceLocation atStartLoc);
// Iterator access to instance/class properties.
using prop_iterator = specific_decl_iterator<ObjCPropertyDecl>;
virtual void collectPropertiesToImplement(PropertyMap &PM,
PropertyDeclOrder &PO) const {}
- SourceLocation getAtStartLoc() const { return AtStart; }
- void setAtStartLoc(SourceLocation Loc) { AtStart = Loc; }
+ SourceLocation getAtStartLoc() const { return ObjCContainerDeclBits.AtStart; }
- // Marks the end of the container.
- SourceRange getAtEndRange() const {
- return AtEnd;
+ void setAtStartLoc(SourceLocation Loc) {
+ ObjCContainerDeclBits.AtStart = Loc;
}
- void setAtEndRange(SourceRange atEnd) {
- AtEnd = atEnd;
- }
+ // Marks the end of the container.
+ SourceRange getAtEndRange() const { return AtEnd; }
+
+ void setAtEndRange(SourceRange atEnd) { AtEnd = atEnd; }
SourceRange getSourceRange() const override LLVM_READONLY {
- return SourceRange(AtStart, getAtEndRange().getEnd());
+ return SourceRange(getAtStartLoc(), getAtEndRange().getEnd());
}
// Implement isa/cast/dyncast/etc.
// ObjCInterfaceDecl
//===----------------------------------------------------------------------===//
+ObjCContainerDecl::ObjCContainerDecl(Kind DK, DeclContext *DC,
+ IdentifierInfo *Id, SourceLocation nameLoc,
+ SourceLocation atStartLoc)
+ : NamedDecl(DK, DC, nameLoc, Id), DeclContext(DK) {
+ setAtStartLoc(atStartLoc);
+}
+
void ObjCContainerDecl::anchor() {}
/// getIvarDecl - This method looks up an ivar in this ContextDecl.
// ObjCMethodDecl
//===----------------------------------------------------------------------===//
+ObjCMethodDecl::ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,
+ Selector SelInfo, QualType T,
+ TypeSourceInfo *ReturnTInfo,
+ DeclContext *contextDecl, bool isInstance,
+ bool isVariadic, bool isPropertyAccessor,
+ bool isImplicitlyDeclared, bool isDefined,
+ ImplementationControl impControl,
+ bool HasRelatedResultType)
+ : NamedDecl(ObjCMethod, contextDecl, beginLoc, SelInfo),
+ DeclContext(ObjCMethod), MethodDeclType(T), ReturnTInfo(ReturnTInfo),
+ DeclEndLoc(endLoc) {
+ // See the comment in ObjCMethodFamilyBitfields about
+ // ObjCMethodFamilyBitWidth for why we check this.
+ static_assert(
+ static_cast<unsigned>(ObjCMethodDeclBits.ObjCMethodFamilyBitWidth) ==
+ static_cast<unsigned>(ObjCMethodFamilyBitWidth),
+ "ObjCMethodDeclBitfields::ObjCMethodFamilyBitWidth and "
+ "ObjCMethodFamilyBitWidth do not match!");
+
+ // Initialized the bits stored in DeclContext.
+ ObjCMethodDeclBits.Family =
+ static_cast<ObjCMethodFamily>(InvalidObjCMethodFamily);
+ setInstanceMethod(isInstance);
+ setVariadic(isVariadic);
+ setPropertyAccessor(isPropertyAccessor);
+ setDefined(isDefined);
+ setIsRedeclaration(false);
+ setHasRedeclaration(false);
+ setDeclImplementation(impControl);
+ setObjCDeclQualifier(OBJC_TQ_None);
+ setRelatedResultType(HasRelatedResultType);
+ setSelLocsKind(SelLoc_StandardNoSpace);
+ setOverriding(false);
+ setHasSkippedBody(false);
+
+ setImplicit(isImplicitlyDeclared);
+}
+
ObjCMethodDecl *ObjCMethodDecl::Create(
ASTContext &C, SourceLocation beginLoc, SourceLocation endLoc,
Selector SelInfo, QualType T, TypeSourceInfo *ReturnTInfo,
void ObjCMethodDecl::setAsRedeclaration(const ObjCMethodDecl *PrevMethod) {
assert(PrevMethod);
getASTContext().setObjCMethodRedeclaration(PrevMethod, this);
- IsRedeclaration = true;
- PrevMethod->HasRedeclaration = true;
+ setIsRedeclaration(true);
+ PrevMethod->setHasRedeclaration(true);
}
void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C,
if (isImplicit())
return setParamsAndSelLocs(C, Params, llvm::None);
- SelLocsKind = hasStandardSelectorLocs(getSelector(), SelLocs, Params,
- DeclEndLoc);
- if (SelLocsKind != SelLoc_NonStandard)
+ setSelLocsKind(hasStandardSelectorLocs(getSelector(), SelLocs, Params,
+ DeclEndLoc));
+ if (getSelLocsKind() != SelLoc_NonStandard)
return setParamsAndSelLocs(C, Params, llvm::None);
setParamsAndSelLocs(C, Params, SelLocs);
ObjCMethodDecl *ObjCMethodDecl::getNextRedeclarationImpl() {
ASTContext &Ctx = getASTContext();
ObjCMethodDecl *Redecl = nullptr;
- if (HasRedeclaration)
+ if (hasRedeclaration())
Redecl = const_cast<ObjCMethodDecl*>(Ctx.getObjCMethodRedeclaration(this));
if (Redecl)
return Redecl;
}
ObjCMethodFamily ObjCMethodDecl::getMethodFamily() const {
- auto family = static_cast<ObjCMethodFamily>(Family);
+ auto family = static_cast<ObjCMethodFamily>(ObjCMethodDeclBits.Family);
if (family != static_cast<unsigned>(InvalidObjCMethodFamily))
return family;
case ObjCMethodFamilyAttr::OMF_mutableCopy: family = OMF_mutableCopy; break;
case ObjCMethodFamilyAttr::OMF_new: family = OMF_new; break;
}
- Family = static_cast<unsigned>(family);
+ ObjCMethodDeclBits.Family = family;
return family;
}
}
// Cache the result.
- Family = static_cast<unsigned>(family);
+ ObjCMethodDeclBits.Family = family;
return family;
}