From d9096704dfa84aea94bb6ac2ffa02d88fa546bfa Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 22 Apr 2016 22:01:43 -0700 Subject: add an ArenaVector for internal array allocations in expression nodes --- src/ast_utils.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/ast_utils.h') diff --git a/src/ast_utils.h b/src/ast_utils.h index 66dbf039a..5b569435e 100644 --- a/src/ast_utils.h +++ b/src/ast_utils.h @@ -136,6 +136,16 @@ struct ExpressionManipulator { static void nop(InputType* target) { convert(target); } + + // Convert a node that allocates + template + static OutputType* convert(InputType *input, MixedArena& allocator) { + assert(sizeof(OutputType) <= sizeof(InputType)); + input->~InputType(); // arena-allocaed, so no destructor, but avoid UB. + OutputType* output = (OutputType*)(input); + new (output) OutputType(allocator); + return output; + } }; struct ExpressionAnalyzer { -- cgit v1.2.3