[cfe-dev] C++ new expression

Sebastian Redl sebastian.redl at getdesigned.at
Wed Nov 12 15:06:16 PST 2008


Hi,

I'm currently implementing parsing new and delete, and I need a bit of help.
The grammar of new-expression means that at one point, I have to 
distinguish between

'(' expression-list ')' # new-placement
and
'(' type-id ')' # alternate form of specifying the type

type-id is a normal C++ type-id, like it appears in cast expressions. 
expression-list is an argument list as it appears in function calls.

Is there anything already in the parser that helps me disambiguate 
between the two?



Also, the prototype of the Action callback for the new expression now 
looks like this:

  virtual ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
                                 SourceLocation PlacementLParen,
                                 ExprTy **PlacementArgs, unsigned 
NumPlaceArgs,
                                 SourceLocation PlacementRParen,
                                 SourceLocation TyStart, TypeTy *Ty,
                                 ExprTy **ArraySizes, unsigned NumDims,
                                 SourceLocation TyEnd,
                                 SourceLocation ConstructorLParen,
                                 ExprTy **ConstructorArgs, unsigned 
NumConsArgs,
                                 SourceLocation ConstructorRParen) {

StartLoc is the start of the entire expression
UseGlobal indicates whether ::new was used
Placement* are the placement new arguments
Ty* and ArraySizes/NumDims are for the actual type of the allocation 
(this feels wrong, somehow)
Constructor* are for the constructor arguments

This is awfully large. Do you have any ideas how to better structure 
this information?

Thanks,
Sebastian



More information about the cfe-dev mailing list