[cfe-dev] Tentative typeid Parser/AST implementation
sebastian.redl at getdesigned.at
Tue Nov 11 07:11:44 CST 2008
Doug Gregor wrote:
> One trick I found while looking at this... instead of having a bit for
> isTypeOp, you can split the SourceRange into two SourceLocations:
> SourceLocation OpLoc; // location of the 'typeid', 'sizeof', or 'alignof'
> SourceLocation RParenLoc; // location of the right paren, if this
> we're storing a type
> When RParenLoc is a valid location, the Operand is a type and
> RParenLoc will be the source location of the right paren. When
> RParenLoc is invalid, the Operand is an expression (and the
> expression's getSourceRange will tell us where the end of the
> expression is). getSourceRange gets slightly more complicated, but
> we'll save ourselves 4 bytes per typeid/sizeof/alignof.
I can do that for sizeof/alignof, but not really for typeid, because the
right paren is part of typeid's own syntax. In other words, "typeid a +
2" is illegal code. I'd have to do some ugly trickery to have a valid
typeid parsed as a parenthesized expression - do I really want to do this?
Also, we don't save anything for sizeof/alignof, because there's already
a boolean (isSizeof) there, and I can collapse that to a single bit,
which gives me plenty of space for the isTypeOperand bit.
More information about the cfe-dev