[cfe-dev] Tentative typeid Parser/AST implementation

Chris Lattner clattner at apple.com
Tue Nov 11 08:59:58 PST 2008


On Nov 11, 2008, at 5:15 AM, Doug Gregor wrote:

> 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.

This is a nice savings, but I wouldn't worry about it right now.  I'd  
rather design the ASTs for clarity and simplicity, and we can micro- 
optimize them later when clang is more "complete".  For example, it  
would be easy to steal a few bits from Stmt to hold bitfields for the  
subclasses if needed.

-Chris



More information about the cfe-dev mailing list