[cfe-dev] Tentative typeid Parser/AST implementation

Doug Gregor doug.gregor at gmail.com
Mon Nov 10 07:05:18 PST 2008


On Sun, Nov 9, 2008 at 2:49 PM, Argiris Kirtzidis <akyrtzi at gmail.com> wrote:
> Hi Sebastian,
>
> Sebastian Redl wrote:
>>
>> Attached patch implements parsing and AST support for typeid. It's not
>> complete in that the type of a typeid expression is const void instead
>> of const std::type_info, but otherwise everything should be correct.
>> However, since this is my first big change of the parser and AST, I
>> might well have overlooked something.
>
> Your approach is not wrong, but I think that is better for consistency
> if you implement typeid in a similar way as sizeof/alignof is implemented.
> sizeof for type calls Action.ActOnSizeOfAlignOfTypeExpr (creating a
> SizeOfAlignOfTypeExpr node), while sizeof for expression calls
> Action.ActOnUnaryOp (creating a UnaryOperator expression node).

Personally, I think the approach taken by alignof and sizeof is not
ideal. If one wants to look through the AST to find sizeof nodes, for
example, you currently have to do a strange two-step of detecting
UnaryOperator or SizeofAlignOfTypeExpr and then check auxiliary fields
to figure out if you have 'sizeof'. The control flow is very messy.
I'd rather see this split out into SizeofExpr and AlignOfExpr classes,
each of which has a similar implementation to Sebastian's
CXXTypeidExpr.

  - Doug



More information about the cfe-dev mailing list