On Jan 20, 2009, at 1:46 PM, Douglas Gregor wrote: > > On Jan 20, 2009, at 1:33 PM, Sebastian Redl wrote: > >> Steve Naroff wrote: >>> Author: snaroff >>> Date: Tue Jan 20 13:53:53 2009 >>> New Revision: 62605 >>> >>> URL: http://llvm.org/viewvc/llvm-project?rev=62605&view=rev >>> Log: >>> Allocate expresssions through ASTContext (still more work to do). >>> >>> = >>> = >>> = >>> = >>> = >>> = >>> = >>> = >>> = >>> = >>> ==================================================================== >>> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) >>> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jan 20 13:53:53 2009 >>> @@ -373,11 +373,14 @@ >>> DeclRefExpr *Sema::BuildDeclRefExpr(NamedDecl *D, QualType Ty, >>> SourceLocation Loc, >>> bool TypeDependent, bool >>> ValueDependent, >>> const CXXScopeSpec *SS) { >>> - if (SS && !SS->isEmpty()) >>> - return new QualifiedDeclRefExpr(D, Ty, Loc, TypeDependent, >>> ValueDependent, >>> - SS->getRange().getBegin()); >>> - else >>> - return new DeclRefExpr(D, Ty, Loc, TypeDependent, >>> ValueDependent); >>> + if (SS && !SS->isEmpty()) { >>> + void *Mem = >>> Context.getAllocator().Allocate<QualifiedDeclRefExpr>(); >>> + return new (Mem) QualifiedDeclRefExpr(D, Ty, Loc, >>> TypeDependent, >>> + ValueDependent, SS->getRange().getBegin()); >>> + } else { >>> + void *Mem = Context.getAllocator().Allocate<DeclRefExpr>(); >>> + return new (Mem) DeclRefExpr(D, Ty, Loc, TypeDependent, >>> ValueDependent); >>> + } >>> } >>> >>> >> >> 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*. >
Fine with me (I was focused more on performance than aesthetics:-) I can convert over to user-defined placement new's. Do you think we should convert Decl's over? snaroff > - Doug _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
