[cfe-dev] Strange inconsistency between sizeof/typeof and type_of_type and type_of_expr.

Sebastian Redl sebastian.redl at getdesigned.at
Mon Jan 5 16:06:06 PST 2009


Paolo Bolzoni wrote:
> dear clang-dev,
>
> I am seeing a strange inconsistency between sizeof/typeof as expression and
> __typeof() as type.
>
> The former is programmed with a single class clang::SizeOfAlignOfExpr with
> two bool functions isSizeOf() and isArgumentType() to distinguish the four
> combinations.
>
> The latter is instead a pair of classes, clang::TypeOfType and
> clang::TypeOfExpr.
>
> Why this implementation difference?
>   
Historical. SizeOfAlignOfExpr was originally two classes, one for types
and one for expressions (actually, it used UnaryOperatorExpr for
classes). When I implemented CXXTypeIdExpr I chose to make just one
class, not being aware of the others. Then I found the SizeOfAlignOf
handling and didn't like that one case was its own expression node, and
the other part of UnaryExpression. It also led to a lot of special cases
in the handling of UnaryOperator. So, with encouragement from Chris, I
moved the sizeof/alignof expr functionality from UnaryOperator to
SizeOfAlignOfExpr.
TypeOfType/Expr, being a Type and not an Expr and not being an
UnaryOperator, didn't come up.

The advantage of having separate classes is that each class is simpler.
But the advantage of having merged classes is that there are fewer
classes. Given the number of times there is a switch on the expression
type in Clang, this leads to a lot less code duplication in various
areas of the codebase.

Here's the commit of TypeIdExpr:
http://www.mail-archive.com/cfe-commits@cs.uiuc.edu/msg02550.html

And here's the SizeOfAlignOfExpr merge:
http://www.mail-archive.com/cfe-commits@cs.uiuc.edu/msg02538.html

Sebastian



More information about the cfe-dev mailing list