diff options
Diffstat (limited to 'src/ast_utils.h')
-rw-r--r-- | src/ast_utils.h | 10 |
1 files changed, 10 insertions, 0 deletions
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<InputType, Nop>(target); } + + // Convert a node that allocates + template<typename InputType, typename OutputType> + 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 { |