[cfe-dev] Re-setting a bitfield width expression.

Enea Zaffanella zaffanella at cs.unipr.it
Thu Jul 7 23:22:18 PDT 2011


We have a question regarding the current interface for FieldDecl.

For the case of in-class member initializers, we have the following methods:

  bool hasInClassInitializer();
  Expr *getInClassInitializer() const;
  void setInClassInitializer(Expr *Init);
  void removeInClassInitializer();

The last method is needed because setInClassInitializer has an assertion
preventing resetting the expression if it was already set.

For the case of bitfields, we have:

  bool isBitField() const;
  Expr *getBitWidth() const;
  void setBitWidth(Expr *BW);

Method setBitWidth has a similar assertion preventing a reset, but in
this case there is no method removeBitWidth: once the bitfield width is
set, there is no way (in debugging mode) to reset it.

In our application (working at the source code level) we sometimes
replace expressions in the AST by equivalent ones and this also happens
for bitfield width expressions.
Would it be OK if we add in a method such as the following:

void removeBitWidth() {
  assert(isBitField() && "no bitwidth to remove");
  InitializerOrBitWidth.setPointer(0);
}

As an alternative (which is enough for our purposes), we could weaken
the assertion in setBitWidth as follows:

  void setBitWidth(Expr *BW) {
    assert(!hasInClassInitializer() &&
           "in-class initializer already set");
    InitializerOrBitWidth.setPointer(BW);
    InitializerOrBitWidth.setInt(1);
  }


While at it, we noted a naming mismatch between methods isBitField
(Field is capitalized here) and isUnnamedBitfield (field is not
capitalized). It looks like elsewhere the second form was preferred.
Is it OK if we change isBitField to isBitfield for consistency?

Regards,
Enea.



More information about the cfe-dev mailing list