diff options
Diffstat (limited to 'include/clang/AST/Decl.h')
-rw-r--r-- | include/clang/AST/Decl.h | 59 |
1 files changed, 28 insertions, 31 deletions
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index a7bf599636..69c4b37224 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -2093,25 +2093,26 @@ class FieldDecl : public DeclaratorDecl { bool Mutable : 1; mutable unsigned CachedFieldIndex : 31; - /// \brief A pointer to either the in-class initializer for this field (if - /// the boolean value is false), or the bit width expression for this bit - /// field (if the boolean value is true). + /// \brief An InClassInitStyle value, and either a bit width expression (if + /// the InClassInitStyle value is ICIS_NoInit), or a pointer to the in-class + /// initializer for this field (otherwise). /// /// We can safely combine these two because in-class initializers are not /// permitted for bit-fields. /// - /// If the boolean is false and the initializer is null, then this field has - /// an in-class initializer which has not yet been parsed and attached. - llvm::PointerIntPair<Expr *, 1, bool> InitializerOrBitWidth; + /// If the InClassInitStyle is not ICIS_NoInit and the initializer is null, + /// then this field has an in-class initializer which has not yet been parsed + /// and attached. + llvm::PointerIntPair<Expr *, 2, unsigned> InitializerOrBitWidth; protected: FieldDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, - bool HasInit) + InClassInitStyle InitStyle) : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc), Mutable(Mutable), CachedFieldIndex(0), - InitializerOrBitWidth(BW, !HasInit) { - assert(!(BW && HasInit) && "got initializer for bitfield"); + InitializerOrBitWidth(BW, InitStyle) { + assert((!BW || InitStyle == ICIS_NoInit) && "got initializer for bitfield"); } public: @@ -2119,7 +2120,7 @@ public: SourceLocation StartLoc, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo, Expr *BW, bool Mutable, - bool HasInit); + InClassInitStyle InitStyle); static FieldDecl *CreateDeserialized(ASTContext &C, unsigned ID); @@ -2130,12 +2131,10 @@ public: /// isMutable - Determines whether this field is mutable (C++ only). bool isMutable() const { return Mutable; } - /// \brief Set whether this field is mutable (C++ only). - void setMutable(bool M) { Mutable = M; } - /// isBitfield - Determines whether this field is a bitfield. bool isBitField() const { - return InitializerOrBitWidth.getInt() && InitializerOrBitWidth.getPointer(); + return getInClassInitStyle() == ICIS_NoInit && + InitializerOrBitWidth.getPointer(); } /// @brief Determines whether this is an unnamed bitfield. @@ -2151,39 +2150,34 @@ public: return isBitField() ? InitializerOrBitWidth.getPointer() : 0; } unsigned getBitWidthValue(const ASTContext &Ctx) const; - void setBitWidth(Expr *BW) { - assert(!InitializerOrBitWidth.getPointer() && - "bit width or initializer already set"); - InitializerOrBitWidth.setPointer(BW); - InitializerOrBitWidth.setInt(1); - } - /// removeBitWidth - Remove the bitfield width from this member. - void removeBitWidth() { - assert(isBitField() && "no bit width to remove"); - InitializerOrBitWidth.setPointer(0); + + /// getInClassInitStyle - Get the kind of (C++11) in-class initializer which + /// this field has. + InClassInitStyle getInClassInitStyle() const { + return static_cast<InClassInitStyle>(InitializerOrBitWidth.getInt()); } - /// hasInClassInitializer - Determine whether this member has a C++0x in-class + /// hasInClassInitializer - Determine whether this member has a C++11 in-class /// initializer. bool hasInClassInitializer() const { - return !InitializerOrBitWidth.getInt(); + return getInClassInitStyle() != ICIS_NoInit; } - /// getInClassInitializer - Get the C++0x in-class initializer for this + /// getInClassInitializer - Get the C++11 in-class initializer for this /// member, or null if one has not been set. If a valid declaration has an /// in-class initializer, but this returns null, then we have not parsed and /// attached it yet. Expr *getInClassInitializer() const { return hasInClassInitializer() ? InitializerOrBitWidth.getPointer() : 0; } - /// setInClassInitializer - Set the C++0x in-class initializer for this + /// setInClassInitializer - Set the C++11 in-class initializer for this /// member. void setInClassInitializer(Expr *Init); - /// removeInClassInitializer - Remove the C++0x in-class initializer from this + /// removeInClassInitializer - Remove the C++11 in-class initializer from this /// member. void removeInClassInitializer() { - assert(!InitializerOrBitWidth.getInt() && "no initializer to remove"); + assert(hasInClassInitializer() && "no initializer to remove"); InitializerOrBitWidth.setPointer(0); - InitializerOrBitWidth.setInt(1); + InitializerOrBitWidth.setInt(ICIS_NoInit); } /// getParent - Returns the parent of this field declaration, which @@ -2202,6 +2196,9 @@ public: static bool classof(const Decl *D) { return classofKind(D->getKind()); } static bool classof(const FieldDecl *D) { return true; } static bool classofKind(Kind K) { return K >= firstField && K <= lastField; } + + friend class ASTDeclReader; + friend class ASTDeclWriter; }; /// EnumConstantDecl - An instance of this object exists for each enum constant |