Strange inconsistency between sizeof/typeof and type_of_type and type_of_expr.

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?
Wasn't easier implementing four classes also for the first case?
Like 'sizeof_expr, sizeof_type, typeof_expr, typeof_type.'

pb

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?

No compelling reason.

Wasn't easier implementing four classes also for the first case?

classes were written at different times by different people (I recall writing the TypeOfType/TypeOfExpr AST's).

Like 'sizeof_expr, sizeof_type, typeof_expr, typeof_type.'

Unifying them is fine with me (if you'd like to pursue it).

snaroff

And CXXTypeidExpr is another one of these. Unifying them would help clean things up.

  - Doug

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