[cfe-commits] r62605 - in /cfe/trunk: include/clang/AST/DeclBase.h lib/AST/DeclBase.cpp lib/Sema/SemaExpr.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Tue Jan 20 14:23:23 PST 2009


Douglas Gregor wrote:
>
> On Jan 20, 2009, at 1:33 PM, Sebastian Redl wrote:
>
>>
>> Oh, dear. Shouldn't we write Create() functions like decls use? Or are
>> the few places where Exprs and Stmts are allocated not worth it?
>>
>> How about a placement new?
>>
>> void *operator new(size_t bytes, ASTContext& C) {
>>  return C.getAllocator().Allocate(bytes, some_default_alignment);
>> }
>> // This one is not really necessary, as it cannot be called directly. It
>> is called implicitly
>> // by the compiler if the constructor in a placement new expression
>> throws.
>> void operator delete(void *ptr, ASTContext& C) {
>>  C.getAllocator().Deallocate(ptr);
>> }
>>
>> This allows this nice syntax for creating the nodes:
>>
>> return new (Context) QualifiedDeclRefExpr(D, Ty, Loc, ...);
>
>
> I like this a *lot*.

OK, I just checked a slightly better and corrected version of this in.
It's declared in ASTContext.h, so you can use it everywhere ASTContext
itself is available.

I also converted ActOnCharacterConstant and ActOnNumericConstant to use
this instead of the dance, for test purposes.

Sebastian




More information about the cfe-commits mailing list