[cfe-dev] Tentative typeid Parser/AST implementation
doug.gregor at gmail.com
Tue Nov 11 07:15:39 CST 2008
On Tue, Nov 11, 2008 at 8:11 AM, Sebastian Redl
<sebastian.redl at getdesigned.at> wrote:
> 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?
Oh, ick... then we certainly don't want to do it for typeid.
> 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.
I guess that depends... if you're planning to make sizeof and alignof
different AST nodes, then we can eliminate the bit for isSizeOf and
make the structures smaller than they used to be. If sizeof and
alignof are the same AST node with an isSizeOf bit, then of course the
isTypeOperand bit is free.
More information about the cfe-dev