aboutsummaryrefslogtreecommitdiff
path: root/include/clang/AST/DeclObjC.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/clang/AST/DeclObjC.h')
-rw-r--r--include/clang/AST/DeclObjC.h191
1 files changed, 86 insertions, 105 deletions
diff --git a/include/clang/AST/DeclObjC.h b/include/clang/AST/DeclObjC.h
index c1cc726e3152..5b57411f9785 100644
--- a/include/clang/AST/DeclObjC.h
+++ b/include/clang/AST/DeclObjC.h
@@ -137,62 +137,17 @@ public:
/// the above methods are setMenu:, menu, replaceSubview:with:, and defaultMenu.
///
class ObjCMethodDecl : public NamedDecl, public DeclContext {
+ // This class stores some data in DeclContext::ObjCMethodDeclBits
+ // to save some space. Use the provided accessors to access it.
+
public:
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
@@ -203,7 +158,7 @@ private:
/// 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
@@ -220,21 +175,14 @@ private:
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 {
@@ -244,10 +192,10 @@ private:
/// 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.
@@ -297,36 +245,50 @@ public:
}
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.
SourceLocation getDeclaratorEndLoc() const { return DeclEndLoc; }
// Location information, modeled after the Stmt API.
- SourceLocation getLocStart() const LLVM_READONLY { return getLocation(); }
- SourceLocation getLocEnd() const LLVM_READONLY;
+ SourceLocation getBeginLoc() const LLVM_READONLY { return getLocation(); }
+ SourceLocation getEndLoc() const LLVM_READONLY;
SourceRange getSourceRange() const override LLVM_READONLY {
- return SourceRange(getLocation(), getLocEnd());
+ return SourceRange(getLocation(), getEndLoc());
}
SourceLocation getSelectorStartLoc() const {
if (isImplicit())
- return getLocStart();
+ return getBeginLoc();
return getSelectorLoc(0);
}
@@ -407,6 +369,14 @@ public:
NumParams);
}
+ ParmVarDecl *getParamDecl(unsigned Idx) {
+ assert(Idx < NumParams && "Index out of bounds!");
+ return getParams()[Idx];
+ }
+ const ParmVarDecl *getParamDecl(unsigned Idx) const {
+ return const_cast<ObjCMethodDecl *>(this)->getParamDecl(Idx);
+ }
+
/// Sets the method's parameters and selector source locations.
/// If the method is implicit (not coming from source) \p SelLocs is
/// ignored.
@@ -449,18 +419,26 @@ public:
/// 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.
///
@@ -469,8 +447,8 @@ public:
/// 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.
///
@@ -484,8 +462,10 @@ public:
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.
///
@@ -496,11 +476,11 @@ public:
// 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 {
@@ -534,6 +514,9 @@ public:
/// Returns whether this specific method is a definition.
bool isThisDeclarationADefinition() const { return hasBody(); }
+ /// Is this method defined in the NSObject base class?
+ bool definedInNSObject(const ASTContext &) const;
+
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classofKind(Kind K) { return K == ObjCMethod; }
@@ -984,7 +967,8 @@ public:
/// ObjCProtocolDecl, and ObjCImplDecl.
///
class ObjCContainerDecl : public NamedDecl, public DeclContext {
- SourceLocation AtStart;
+ // This class stores some data in DeclContext::ObjCContainerDeclBits
+ // to save some space. Use the provided accessors to access it.
// 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.
@@ -993,10 +977,8 @@ class ObjCContainerDecl : public NamedDecl, public DeclContext {
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>;
@@ -1130,20 +1112,19 @@ public:
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.
@@ -2831,7 +2812,7 @@ public:
SourceRange getSourceRange() const override LLVM_READONLY;
- SourceLocation getLocStart() const LLVM_READONLY { return AtLoc; }
+ SourceLocation getBeginLoc() const LLVM_READONLY { return AtLoc; }
void setAtLoc(SourceLocation Loc) { AtLoc = Loc; }
ObjCPropertyDecl *getPropertyDecl() const {