diff options
author | Ben Smith <binjimin@gmail.com> | 2017-03-22 21:14:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-22 21:14:16 -0700 |
commit | 192fbd023a542f2e6d7a737ac5412e392dd0e45e (patch) | |
tree | 7d8e7e84d6a351b175fa6c132493cda3d8be4cd2 /src/ast-parser-lexer-shared.h | |
parent | f8c3d6027dd64c7c3c962aa1d4bfc50e6ecc4a8c (diff) | |
download | wabt-192fbd023a542f2e6d7a737ac5412e392dd0e45e.tar.gz wabt-192fbd023a542f2e6d7a737ac5412e392dd0e45e.tar.bz2 wabt-192fbd023a542f2e6d7a737ac5412e392dd0e45e.zip |
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.)
Diffstat (limited to 'src/ast-parser-lexer-shared.h')
-rw-r--r-- | src/ast-parser-lexer-shared.h | 71 |
1 files changed, 38 insertions, 33 deletions
diff --git a/src/ast-parser-lexer-shared.h b/src/ast-parser-lexer-shared.h index cb0f7bd8..b06da3c2 100644 --- a/src/ast-parser-lexer-shared.h +++ b/src/ast-parser-lexer-shared.h @@ -19,6 +19,8 @@ #include <stdarg.h> +#include <memory> + #include "ast.h" #include "ast-lexer.h" #include "common.h" @@ -49,30 +51,30 @@ struct TextList { }; struct OptionalExport { - Export export_; + std::unique_ptr<Export> export_; bool has_export; }; struct ExportedFunc { - Func* func; + std::unique_ptr<Func> func; OptionalExport export_; }; struct ExportedGlobal { - Global global; + std::unique_ptr<Global> global; OptionalExport export_; }; struct ExportedTable { - Table table; - ElemSegment elem_segment; + std::unique_ptr<Table> table; + std::unique_ptr<ElemSegment> elem_segment; OptionalExport export_; bool has_elem_segment; }; struct ExportedMemory { - Memory memory; - DataSegment data_segment; + std::unique_ptr<Memory> memory; + std::unique_ptr<DataSegment> data_segment; OptionalExport export_; bool has_data_segment; }; @@ -87,16 +89,24 @@ enum class FuncFieldType { }; struct BoundType { + WABT_DISALLOW_COPY_AND_ASSIGN(BoundType); + BoundType(); + ~BoundType(); + Location loc; StringSlice name; Type type; }; struct FuncField { + WABT_DISALLOW_COPY_AND_ASSIGN(FuncField); + FuncField(); + ~FuncField(); + FuncFieldType type; union { Expr* first_expr; /* WABT_FUNC_FIELD_TYPE_EXPRS */ - TypeVector types; /* WABT_FUNC_FIELD_TYPE_*_TYPES */ + TypeVector* types; /* WABT_FUNC_FIELD_TYPE_*_TYPES */ BoundType bound_type; /* WABT_FUNC_FIELD_TYPE_BOUND_{LOCAL, PARAM} */ }; struct FuncField* next; @@ -112,40 +122,40 @@ union Token { /* non-terminals */ /* some of these use pointers to keep the size of Token down; copying the tokens is a hotspot when parsing large files. */ - Action action; - Block block; + Action* action; + Block* block; Command* command; - CommandVector commands; + CommandPtrVector* commands; Const const_; - ConstVector consts; - DataSegment data_segment; - ElemSegment elem_segment; - Export export_; - ExportedFunc exported_func; - ExportedGlobal exported_global; - ExportedMemory exported_memory; - ExportedTable exported_table; + ConstVector* consts; + DataSegment* data_segment; + ElemSegment* elem_segment; + Export* export_; + ExportedFunc* exported_func; + ExportedGlobal* exported_global; + ExportedMemory* exported_memory; + ExportedTable* exported_table; Expr* expr; ExprList expr_list; FuncField* func_fields; Func* func; - FuncSignature func_sig; - FuncType func_type; - Global global; + FuncSignature* func_sig; + FuncType* func_type; + Global* global; Import* import; Limits limits; - OptionalExport optional_export; - Memory memory; + OptionalExport* optional_export; + Memory* memory; Module* module; - RawModule raw_module; + RawModule* raw_module; Script* script; - Table table; + Table* table; TextList text_list; - TypeVector types; + TypeVector* types; uint32_t u32; uint64_t u64; Var var; - VarVector vars; + VarVector* vars; }; struct AstParser { @@ -175,11 +185,6 @@ void ast_format_error(SourceErrorHandler*, AstLexer*, const char* format, va_list); -void destroy_optional_export(OptionalExport*); -void destroy_exported_func(ExportedFunc*); -void destroy_exported_global(ExportedFunc*); -void destroy_exported_memory(ExportedMemory*); -void destroy_exported_table(ExportedTable*); void destroy_func_fields(FuncField*); void destroy_text_list(TextList*); |