Index: cfe/trunk/include/clang/AST/DeclObjC.h =================================================================== --- cfe/trunk/include/clang/AST/DeclObjC.h +++ cfe/trunk/include/clang/AST/DeclObjC.h @@ -141,58 +141,10 @@ 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 +155,7 @@ /// 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 +172,14 @@ 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(ObjCMethodDeclBits.SelLocsKind); + } + + void setSelLocsKind(SelectorLocationsKind Kind) { + ObjCMethodDeclBits.SelLocsKind = Kind; } bool hasStandardSelLocs() const { @@ -244,10 +189,10 @@ /// Get a pointer to the stored selector identifiers locations array. /// No locations will be stored if HasStandardSelLocs is true. SourceLocation *getStoredSelLocs() { - return reinterpret_cast(getParams() + NumParams); + return reinterpret_cast(getParams() + NumParams); } const SourceLocation *getStoredSelLocs() const { - return reinterpret_cast(getParams() + NumParams); + return reinterpret_cast(getParams() + NumParams); } /// Get a pointer to the stored selector identifiers locations array. @@ -297,21 +242,35 @@ } ObjCDeclQualifier getObjCDeclQualifier() const { - return ObjCDeclQualifier(objcDeclQualifier); + return static_cast(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. @@ -449,18 +408,26 @@ /// 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 +436,8 @@ /// 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 +451,10 @@ SmallVectorImpl &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 +465,11 @@ // 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 { @@ -984,8 +953,6 @@ /// 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; @@ -993,10 +960,8 @@ 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; @@ -1130,20 +1095,19 @@ 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. Index: cfe/trunk/lib/AST/DeclObjC.cpp =================================================================== --- cfe/trunk/lib/AST/DeclObjC.cpp +++ cfe/trunk/lib/AST/DeclObjC.cpp @@ -65,6 +65,13 @@ // 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. @@ -769,6 +776,44 @@ // 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(ObjCMethodDeclBits.ObjCMethodFamilyBitWidth) == + static_cast(ObjCMethodFamilyBitWidth), + "ObjCMethodDeclBitfields::ObjCMethodFamilyBitWidth and " + "ObjCMethodFamilyBitWidth do not match!"); + + // Initialized the bits stored in DeclContext. + ObjCMethodDeclBits.Family = + static_cast(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, @@ -810,8 +855,8 @@ 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, @@ -846,9 +891,9 @@ 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); @@ -860,7 +905,7 @@ ObjCMethodDecl *ObjCMethodDecl::getNextRedeclarationImpl() { ASTContext &Ctx = getASTContext(); ObjCMethodDecl *Redecl = nullptr; - if (HasRedeclaration) + if (hasRedeclaration()) Redecl = const_cast(Ctx.getObjCMethodRedeclaration(this)); if (Redecl) return Redecl; @@ -938,7 +983,7 @@ } ObjCMethodFamily ObjCMethodDecl::getMethodFamily() const { - auto family = static_cast(Family); + auto family = static_cast(ObjCMethodDeclBits.Family); if (family != static_cast(InvalidObjCMethodFamily)) return family; @@ -954,7 +999,7 @@ case ObjCMethodFamilyAttr::OMF_mutableCopy: family = OMF_mutableCopy; break; case ObjCMethodFamilyAttr::OMF_new: family = OMF_new; break; } - Family = static_cast(family); + ObjCMethodDeclBits.Family = family; return family; } @@ -1025,7 +1070,7 @@ } // Cache the result. - Family = static_cast(family); + ObjCMethodDeclBits.Family = family; return family; } Index: cfe/trunk/lib/Sema/SemaDeclObjC.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaDeclObjC.cpp +++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp @@ -4351,7 +4351,7 @@ // Propagate down the 'related result type' bit from overridden methods. if (RTC != Sema::RTC_Incompatible && overridden->hasRelatedResultType()) - ObjCMethod->SetRelatedResultType(); + ObjCMethod->setRelatedResultType(); // Then merge the declarations. mergeObjCMethodDecls(ObjCMethod, overridden); @@ -4746,7 +4746,7 @@ if (InferRelatedResultType && !ObjCMethod->getReturnType()->isObjCIndependentClassType()) - ObjCMethod->SetRelatedResultType(); + ObjCMethod->setRelatedResultType(); } if (MethodDefinition && Index: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp =================================================================== --- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp +++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp @@ -1007,18 +1007,18 @@ MD->setVariadic(Record.readInt()); MD->setPropertyAccessor(Record.readInt()); MD->setDefined(Record.readInt()); - MD->IsOverriding = Record.readInt(); - MD->HasSkippedBody = Record.readInt(); + MD->setOverriding(Record.readInt()); + MD->setHasSkippedBody(Record.readInt()); - MD->IsRedeclaration = Record.readInt(); - MD->HasRedeclaration = Record.readInt(); - if (MD->HasRedeclaration) + MD->setIsRedeclaration(Record.readInt()); + MD->setHasRedeclaration(Record.readInt()); + if (MD->hasRedeclaration()) Reader.getContext().setObjCMethodRedeclaration(MD, ReadDeclAs()); MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record.readInt()); MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record.readInt()); - MD->SetRelatedResultType(Record.readInt()); + MD->setRelatedResultType(Record.readInt()); MD->setReturnType(Record.readType()); MD->setReturnTypeSourceInfo(GetTypeSourceInfo()); MD->DeclEndLoc = ReadSourceLocation(); @@ -1028,7 +1028,7 @@ for (unsigned I = 0; I != NumParams; ++I) Params.push_back(ReadDeclAs()); - MD->SelLocsKind = Record.readInt(); + MD->setSelLocsKind((SelectorLocationsKind)Record.readInt()); unsigned NumStoredSelLocs = Record.readInt(); SmallVector SelLocs; SelLocs.reserve(NumStoredSelLocs); Index: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp =================================================================== --- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp +++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp @@ -647,12 +647,12 @@ Record.push_back(D->isVariadic()); Record.push_back(D->isPropertyAccessor()); Record.push_back(D->isDefined()); - Record.push_back(D->IsOverriding); - Record.push_back(D->HasSkippedBody); + Record.push_back(D->isOverriding()); + Record.push_back(D->hasSkippedBody()); - Record.push_back(D->IsRedeclaration); - Record.push_back(D->HasRedeclaration); - if (D->HasRedeclaration) { + Record.push_back(D->isRedeclaration()); + Record.push_back(D->hasRedeclaration()); + if (D->hasRedeclaration()) { assert(Context.getObjCMethodRedeclaration(D)); Record.AddDeclRef(Context.getObjCMethodRedeclaration(D)); } @@ -669,7 +669,7 @@ for (const auto *P : D->parameters()) Record.AddDeclRef(P); - Record.push_back(D->SelLocsKind); + Record.push_back(D->getSelLocsKind()); unsigned NumStoredSelLocs = D->getNumStoredSelLocs(); SourceLocation *SelLocs = D->getStoredSelLocs(); Record.push_back(NumStoredSelLocs);