add Codegen.handle_side_effects and apply it on the AST when compiling to CPP (closes #2217)