From 192fbd023a542f2e6d7a737ac5412e392dd0e45e Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Wed, 22 Mar 2017 21:14:16 -0700 Subject: Replace wabt::*vector with std::vector (#366) This propagates through a lot of code since std::vector will call constructors and destructors. In particular, this CL adds many default constructors and destructors to previously POD types. Many of them are only there to construct `Var` and `StringSlice` types, so they likely can be removed when those have their own constructors. Since unions members cannot contain constructors or destructors (without additional implementation), this CL changes those members to pointers instead. (Perhaps in a future CL these will be std::variant instead of union, so the members can be value types again.) --- src/binary-reader-interpreter.cc | 167 ++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 100 deletions(-) (limited to 'src/binary-reader-interpreter.cc') diff --git a/src/binary-reader-interpreter.cc b/src/binary-reader-interpreter.cc index e69acd1c..b8948c0a 100644 --- a/src/binary-reader-interpreter.cc +++ b/src/binary-reader-interpreter.cc @@ -21,6 +21,8 @@ #include #include +#include + #include "binary-reader.h" #include "interpreter.h" #include "type-checker.h" @@ -45,7 +47,7 @@ #define CHECK_GLOBAL(ctx, global_index) \ do { \ - uint32_t max_global_index = (ctx)->global_index_mapping.size; \ + uint32_t max_global_index = (ctx)->global_index_mapping.size(); \ if ((global_index) >= max_global_index) { \ print_error((ctx), "invalid global_index: %d (max %d)", (global_index), \ max_global_index); \ @@ -57,27 +59,21 @@ namespace wabt { namespace { -typedef uint32_t Uint32; -WABT_DEFINE_VECTOR(uint32, Uint32); -WABT_DEFINE_VECTOR(uint32_vector, Uint32Vector); +typedef std::vector Uint32Vector; +typedef std::vector Uint32VectorVector; struct Label { + Label(uint32_t offset, uint32_t fixup_offset); + uint32_t offset; /* branch location in the istream */ uint32_t fixup_offset; }; -WABT_DEFINE_VECTOR(label, Label); + +Label::Label(uint32_t offset, uint32_t fixup_offset) + : offset(offset), fixup_offset(fixup_offset) {} struct Context { - Context() { - WABT_ZERO_MEMORY(typechecker); - WABT_ZERO_MEMORY(label_stack); - WABT_ZERO_MEMORY(func_fixups); - WABT_ZERO_MEMORY(depth_fixups); - WABT_ZERO_MEMORY(istream_writer); - WABT_ZERO_MEMORY(sig_index_mapping); - WABT_ZERO_MEMORY(func_index_mapping); - WABT_ZERO_MEMORY(global_index_mapping); - } + Context(); BinaryReader* reader = nullptr; BinaryErrorHandler* error_handler = nullptr; @@ -85,7 +81,7 @@ struct Context { DefinedInterpreterModule* module = nullptr; DefinedInterpreterFunc* current_func = nullptr; TypeChecker typechecker; - LabelVector label_stack; + std::vector