summaryrefslogtreecommitdiff
path: root/src/ast-parser.y
diff options
context:
space:
mode:
Diffstat (limited to 'src/ast-parser.y')
-rw-r--r--src/ast-parser.y830
1 files changed, 407 insertions, 423 deletions
diff --git a/src/ast-parser.y b/src/ast-parser.y
index 9c5d4eb0..7977586a 100644
--- a/src/ast-parser.y
+++ b/src/ast-parser.y
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <algorithm>
+#include <utility>
#include "ast-parser.h"
#include "ast-parser-lexer-shared.h"
@@ -81,44 +82,40 @@
field->kind = item; \
} while (0)
-#define APPEND_ITEM_TO_VECTOR(module, Kind, kind, kinds, item_ptr) \
- do { \
- Kind* dummy = item_ptr; \
- append_##kind##_ptr_value(&(module)->kinds, &dummy); \
- } while (0)
+#define APPEND_ITEM_TO_VECTOR(module, kinds, item_ptr) \
+ (module)->kinds.push_back(item_ptr)
#define INSERT_BINDING(module, kind, kinds, loc_, name) \
do \
if ((name).start) { \
(module)->kind##_bindings.emplace( \
string_slice_to_string(name), \
- Binding(loc_, (module)->kinds.size - 1)); \
+ Binding(loc_, (module)->kinds.size() - 1)); \
} \
while (0)
#define APPEND_INLINE_EXPORT(module, Kind, loc_, value, index_) \
do \
- if ((value).export_.has_export) { \
+ if ((value)->export_.has_export) { \
ModuleField* export_field; \
APPEND_FIELD_TO_LIST(module, export_field, Export, export_, loc_, \
- (value).export_.export_); \
- export_field->export_.kind = ExternalKind::Kind; \
- export_field->export_.var.loc = loc_; \
- export_field->export_.var.index = index_; \
- APPEND_ITEM_TO_VECTOR(module, Export, export, exports, \
- &export_field->export_); \
+ (value)->export_.export_.release()); \
+ export_field->export_->kind = ExternalKind::Kind; \
+ export_field->export_->var.loc = loc_; \
+ export_field->export_->var.index = index_; \
+ APPEND_ITEM_TO_VECTOR(module, exports, export_field->export_); \
INSERT_BINDING(module, export, exports, export_field->loc, \
- export_field->export_.name); \
+ export_field->export_->name); \
} \
while (0)
-#define CHECK_IMPORT_ORDERING(module, kind, kinds, loc_) \
- do { \
- if ((module)->kinds.size != (module)->num_##kind##_imports) { \
- ast_parser_error( \
- &loc_, lexer, parser, \
- "imports must occur before all non-import definitions"); \
- } \
+#define CHECK_IMPORT_ORDERING(module, kind, kinds, loc_) \
+ do { \
+ if ((module)->kinds.size() != (module)->num_##kind##_imports) { \
+ ast_parser_error( \
+ &loc_, lexer, parser, \
+ "imports must occur before all non-import definitions"); \
+ } \
} while (0)
#define CHECK_END_LABEL(loc, begin_label, end_label) \
@@ -151,12 +148,6 @@ ExprList join_exprs2(Location* loc,
ExprList* expr1,
Expr* expr2);
-FuncField* new_func_field(void) { return new FuncField(); }
-Command* new_command(void) { return new Command(); }
-Module* new_module(void) { return new Module(); }
-Import* new_import(void) { return new Import(); }
-TextListNode* new_text_list_node(void) { return new TextListNode(); }
-
Result parse_const(Type type,
LiteralType literal_type,
const char* s,
@@ -164,7 +155,7 @@ Result parse_const(Type type,
Const* out);
void dup_text_list(TextList* text_list, char** out_data, size_t* out_size);
-bool is_empty_signature(FuncSignature* sig);
+bool is_empty_signature(const FuncSignature* sig);
void append_implicit_func_declaration(Location*,
Module*,
@@ -256,32 +247,36 @@ static bool on_read_binary_error(uint32_t offset, const char* error,
/* These non-terminals use the types below that have destructors, but the
* memory is shared with the lexer, so should not be destroyed. */
%destructor {} ALIGN_EQ_NAT OFFSET_EQ_NAT TEXT VAR NAT INT FLOAT
-%destructor { destroy_block(&$$); } <block>
-%destructor { destroy_command($$); delete $$; } <command>
-%destructor { destroy_command_vector_and_elements(&$$); } <commands>
-%destructor { destroy_const_vector(&$$); } <consts>
-%destructor { destroy_elem_segment(&$$); } <elem_segment>
-%destructor { destroy_export(&$$); } <export_>
-%destructor { destroy_exported_func(&$$); } <exported_func>
-%destructor { destroy_exported_memory(&$$); } <exported_memory>
-%destructor { destroy_exported_table(&$$); } <exported_table>
-%destructor { destroy_expr($$); } <expr>
+%destructor { destroy_string_slice(&$$); } <text>
+%destructor { destroy_string_slice(&$$.text); } <literal>
+%destructor { delete $$; } <action>
+%destructor { delete $$; } <block>
+%destructor { delete $$; } <command>
+%destructor { delete $$; } <commands>
+%destructor { delete $$; } <consts>
+%destructor { delete $$; } <data_segment>
+%destructor { delete $$; } <elem_segment>
+%destructor { delete $$; } <export_>
+%destructor { delete $$; } <exported_func>
+%destructor { delete $$; } <exported_memory>
+%destructor { delete $$; } <exported_table>
+%destructor { delete $$; } <expr>
%destructor { destroy_expr_list($$.first); } <expr_list>
%destructor { destroy_func_fields($$); } <func_fields>
%destructor { delete $$; } <func>
-%destructor { destroy_func_signature(&$$); } <func_sig>
-%destructor { destroy_func_type(&$$); } <func_type>
-%destructor { destroy_import($$); delete $$; } <import>
-%destructor { destroy_data_segment(&$$); } <data_segment>
+%destructor { delete $$; } <func_sig>
+%destructor { delete $$; } <func_type>
+%destructor { delete $$; } <global>
+%destructor { delete $$; } <import>
+%destructor { delete $$; } <optional_export>
+%destructor { delete $$; } <memory>
%destructor { delete $$; } <module>
-%destructor { destroy_raw_module(&$$); } <raw_module>
-%destructor { destroy_string_slice(&$$.text); } <literal>
+%destructor { delete $$; } <raw_module>
%destructor { delete $$; } <script>
-%destructor { destroy_string_slice(&$$); } <text>
%destructor { destroy_text_list(&$$); } <text_list>
-%destructor { destroy_type_vector(&$$); } <types>
-%destructor { destroy_var_vector_and_elements(&$$); } <vars>
+%destructor { delete $$; } <types>
%destructor { destroy_var(&$$); } <var>
+%destructor { delete $$; } <vars>
%nonassoc LOW
@@ -295,14 +290,14 @@ static bool on_read_binary_error(uint32_t offset, const char* error,
non_empty_text_list :
TEXT {
- TextListNode* node = new_text_list_node();
+ TextListNode* node = new TextListNode();
DUPTEXT(node->text, $1);
node->next = nullptr;
$$.first = $$.last = node;
}
| non_empty_text_list TEXT {
$$ = $1;
- TextListNode* node = new_text_list_node();
+ TextListNode* node = new TextListNode();
DUPTEXT(node->text, $2);
node->next = nullptr;
$$.last->next = node;
@@ -333,10 +328,10 @@ quoted_text :
/* Types */
value_type_list :
- /* empty */ { WABT_ZERO_MEMORY($$); }
+ /* empty */ { $$ = new TypeVector(); }
| value_type_list VALUE_TYPE {
$$ = $1;
- append_type_value(&$$, &$2);
+ $$->push_back($2);
}
;
elem_type :
@@ -344,41 +339,51 @@ elem_type :
;
global_type :
VALUE_TYPE {
- WABT_ZERO_MEMORY($$);
- $$.type = $1;
- $$.mutable_ = false;
+ $$ = new Global();
+ $$->type = $1;
+ $$->mutable_ = false;
}
| LPAR MUT VALUE_TYPE RPAR {
- WABT_ZERO_MEMORY($$);
- $$.type = $3;
- $$.mutable_ = true;
+ $$ = new Global();
+ $$->type = $3;
+ $$->mutable_ = true;
}
;
func_type :
LPAR FUNC func_sig RPAR { $$ = $3; }
;
func_sig :
- /* empty */ { WABT_ZERO_MEMORY($$); }
+ /* empty */ { $$ = new FuncSignature(); }
| LPAR PARAM value_type_list RPAR {
- WABT_ZERO_MEMORY($$);
- $$.param_types = $3;
+ $$ = new FuncSignature();
+ $$->param_types = std::move(*$3);
+ delete $3;
}
| LPAR PARAM value_type_list RPAR LPAR RESULT value_type_list RPAR {
- WABT_ZERO_MEMORY($$);
- $$.param_types = $3;
- $$.result_types = $7;
+ $$ = new FuncSignature();
+ $$->param_types = std::move(*$3);
+ delete $3;
+ $$->result_types = std::move(*$7);
+ delete $7;
}
| LPAR RESULT value_type_list RPAR {
- WABT_ZERO_MEMORY($$);
- $$.result_types = $3;
+ $$ = new FuncSignature();
+ $$->result_types = std::move(*$3);
+ delete $3;
}
;
table_sig :
- limits elem_type { $$.elem_limits = $1; }
+ limits elem_type {
+ $$ = new Table();
+ $$->elem_limits = $1;
+ }
;
memory_sig :
- limits { $$.page_limits = $1; }
+ limits {
+ $$ = new Memory();
+ $$->page_limits = $1;
+ }
;
limits :
nat {
@@ -437,10 +442,10 @@ var :
}
;
var_list :
- /* empty */ { WABT_ZERO_MEMORY($$); }
+ /* empty */ { $$ = new VarVector(); }
| var_list var {
$$ = $1;
- append_var_value(&$$, &$2);
+ $$->push_back($2);
}
;
bind_var_opt :
@@ -486,141 +491,117 @@ instr :
;
plain_instr :
UNREACHABLE {
- $$ = new_unreachable_expr();
+ $$ = Expr::CreateUnreachable();
}
| NOP {
- $$ = new_nop_expr();
+ $$ = Expr::CreateNop();
}
| DROP {
- $$ = new_drop_expr();
+ $$ = Expr::CreateDrop();
}
| SELECT {
- $$ = new_select_expr();
+ $$ = Expr::CreateSelect();
}
| BR var {
- $$ = new_br_expr();
- $$->br.var = $2;
+ $$ = Expr::CreateBr($2);
}
| BR_IF var {
- $$ = new_br_if_expr();
- $$->br_if.var = $2;
+ $$ = Expr::CreateBrIf($2);
}
| BR_TABLE var_list var {
- $$ = new_br_table_expr();
- $$->br_table.targets = $2;
- $$->br_table.default_target = $3;
+ $$ = Expr::CreateBrTable($2, $3);
}
| RETURN {
- $$ = new_return_expr();
+ $$ = Expr::CreateReturn();
}
| CALL var {
- $$ = new_call_expr();
- $$->call.var = $2;
+ $$ = Expr::CreateCall($2);
}
| CALL_INDIRECT var {
- $$ = new_call_indirect_expr();
- $$->call_indirect.var = $2;
+ $$ = Expr::CreateCallIndirect($2);
}
| GET_LOCAL var {
- $$ = new_get_local_expr();
- $$->get_local.var = $2;
+ $$ = Expr::CreateGetLocal($2);
}
| SET_LOCAL var {
- $$ = new_set_local_expr();
- $$->set_local.var = $2;
+ $$ = Expr::CreateSetLocal($2);
}
| TEE_LOCAL var {
- $$ = new_tee_local_expr();
- $$->tee_local.var = $2;
+ $$ = Expr::CreateTeeLocal($2);
}
| GET_GLOBAL var {
- $$ = new_get_global_expr();
- $$->get_global.var = $2;
+ $$ = Expr::CreateGetGlobal($2);
}
| SET_GLOBAL var {
- $$ = new_set_global_expr();
- $$->set_global.var = $2;
+ $$ = Expr::CreateSetGlobal($2);
}
| LOAD offset_opt align_opt {
- $$ = new_load_expr();
- $$->load.opcode = $1;
- $$->load.offset = $2;
- $$->load.align = $3;
+ $$ = Expr::CreateLoad($1, $3, $2);
}
| STORE offset_opt align_opt {
- $$ = new_store_expr();
- $$->store.opcode = $1;
- $$->store.offset = $2;
- $$->store.align = $3;
+ $$ = Expr::CreateStore($1, $3, $2);
}
| CONST literal {
- $$ = new_const_expr();
- $$->const_.loc = @1;
+ Const const_;
+ WABT_ZERO_MEMORY(const_);
+ const_.loc = @1;
if (WABT_FAILED(parse_const($1, $2.type, $2.text.start,
- $2.text.start + $2.text.length,
- &$$->const_))) {
+ $2.text.start + $2.text.length, &const_))) {
ast_parser_error(&@2, lexer, parser,
"invalid literal \"" PRIstringslice "\"",
WABT_PRINTF_STRING_SLICE_ARG($2.text));
}
delete [] $2.text.start;
+ $$ = Expr::CreateConst(const_);
}
| UNARY {
- $$ = new_unary_expr();
- $$->unary.opcode = $1;
+ $$ = Expr::CreateUnary($1);
}
| BINARY {
- $$ = new_binary_expr();
- $$->binary.opcode = $1;
+ $$ = Expr::CreateBinary($1);
}
| COMPARE {
- $$ = new_compare_expr();
- $$->compare.opcode = $1;
+ $$ = Expr::CreateCompare($1);
}
| CONVERT {
- $$ = new_convert_expr();
- $$->convert.opcode = $1;
+ $$ = Expr::CreateConvert($1);
}
| CURRENT_MEMORY {
- $$ = new_current_memory_expr();
+ $$ = Expr::CreateCurrentMemory();
}
| GROW_MEMORY {
- $$ = new_grow_memory_expr();
+ $$ = Expr::CreateGrowMemory();
}
;
block_instr :
BLOCK labeling_opt block END labeling_opt {
- $$ = new_block_expr();
- $$->block = $3;
- $$->block.label = $2;
- CHECK_END_LABEL(@5, $$->block.label, $5);
+ $$ = Expr::CreateBlock($3);
+ $$->block->label = $2;
+ CHECK_END_LABEL(@5, $$->block->label, $5);
}
| LOOP labeling_opt block END labeling_opt {
- $$ = new_loop_expr();
- $$->loop = $3;
- $$->loop.label = $2;
- CHECK_END_LABEL(@5, $$->block.label, $5);
+ $$ = Expr::CreateLoop($3);
+ $$->loop->label = $2;
+ CHECK_END_LABEL(@5, $$->loop->label, $5);
}
| IF labeling_opt block END labeling_opt {
- $$ = new_if_expr();
- $$->if_.true_ = $3;
- $$->if_.true_.label = $2;
- CHECK_END_LABEL(@5, $$->block.label, $5);
+ $$ = Expr::CreateIf($3, nullptr);
+ $$->if_.true_->label = $2;
+ CHECK_END_LABEL(@5, $$->if_.true_->label, $5);
}
| IF labeling_opt block ELSE labeling_opt instr_list END labeling_opt {
- $$ = new_if_expr();
- $$->if_.true_ = $3;
- $$->if_.true_.label = $2;
- $$->if_.false_ = $6.first;
- CHECK_END_LABEL(@5, $$->block.label, $5);
- CHECK_END_LABEL(@8, $$->block.label, $8);
+ $$ = Expr::CreateIf($3, $6.first);
+ $$->if_.true_->label = $2;
+ CHECK_END_LABEL(@5, $$->if_.true_->label, $5);
+ CHECK_END_LABEL(@8, $$->if_.true_->label, $8);
}
;
block :
value_type_list instr_list {
- WABT_ZERO_MEMORY($$);
- $$.sig = $1;
- $$.first = $2.first;
+ $$ = new Block();
+ $$->sig = std::move(*$1);
+ delete $1;
+ $$->first = $2.first;
}
;
@@ -633,57 +614,47 @@ expr1 :
$$ = join_exprs2(&@1, &$2, $1);
}
| BLOCK labeling_opt block {
- Expr* expr = new_block_expr();
- expr->block = $3;
- expr->block.label = $2;
+ Expr* expr = Expr::CreateBlock($3);
+ expr->block->label = $2;
$$ = join_exprs1(&@1, expr);
}
| LOOP labeling_opt block {
- Expr* expr = new_loop_expr();
- expr->loop = $3;
- expr->loop.label = $2;
+ Expr* expr = Expr::CreateLoop($3);
+ expr->loop->label = $2;
$$ = join_exprs1(&@1, expr);
}
| IF labeling_opt value_type_list if_ {
$$ = $4;
Expr* if_ = $4.last;
assert(if_->type == ExprType::If);
- if_->if_.true_.label = $2;
- if_->if_.true_.sig = $3;
+ if_->if_.true_->label = $2;
+ if_->if_.true_->sig = std::move(*$3);
+ delete $3;
}
;
if_ :
LPAR THEN instr_list RPAR LPAR ELSE instr_list RPAR {
- Expr* expr = new_if_expr();
- expr->if_.true_.first = $3.first;
- expr->if_.false_ = $7.first;
+ Expr* expr = Expr::CreateIf(new Block($3.first), $7.first);
$$ = join_exprs1(&@1, expr);
}
| LPAR THEN instr_list RPAR {
- Expr* expr = new_if_expr();
- expr->if_.true_.first = $3.first;
+ Expr* expr = Expr::CreateIf(new Block($3.first), nullptr);
$$ = join_exprs1(&@1, expr);
}
| expr LPAR THEN instr_list RPAR LPAR ELSE instr_list RPAR {
- Expr* expr = new_if_expr();
- expr->if_.true_.first = $4.first;
- expr->if_.false_ = $8.first;
+ Expr* expr = Expr::CreateIf(new Block($4.first), $8.first);
$$ = join_exprs2(&@1, &$1, expr);
}
| expr LPAR THEN instr_list RPAR {
- Expr* expr = new_if_expr();
- expr->if_.true_.first = $4.first;
+ Expr* expr = Expr::CreateIf(new Block($4.first), nullptr);
$$ = join_exprs2(&@1, &$1, expr);
}
| expr expr expr {
- Expr* expr = new_if_expr();
- expr->if_.true_.first = $2.first;
- expr->if_.false_ = $3.first;
+ Expr* expr = Expr::CreateIf(new Block($2.first), $3.first);
$$ = join_exprs2(&@1, &$1, expr);
}
| expr expr {
- Expr* expr = new_if_expr();
- expr->if_.true_.first = $2.first;
+ Expr* expr = Expr::CreateIf(new Block($2.first), nullptr);
$$ = join_exprs2(&@1, &$1, expr);
}
;
@@ -714,19 +685,19 @@ const_expr :
func_fields :
func_body
| LPAR RESULT value_type_list RPAR func_body {
- $$ = new_func_field();
+ $$ = new FuncField();
$$->type = FuncFieldType::ResultTypes;
$$->types = $3;
$$->next = $5;
}
| LPAR PARAM value_type_list RPAR func_fields {
- $$ = new_func_field();
+ $$ = new FuncField();
$$->type = FuncFieldType::ParamTypes;
$$->types = $3;
$$->next = $5;
}
| LPAR PARAM bind_var VALUE_TYPE RPAR func_fields {
- $$ = new_func_field();
+ $$ = new FuncField();
$$->type = FuncFieldType::BoundParam;
$$->bound_type.loc = @2;
$$->bound_type.name = $3;
@@ -736,19 +707,19 @@ func_fields :
;
func_body :
instr_list {
- $$ = new_func_field();
+ $$ = new FuncField();
$$->type = FuncFieldType::Exprs;
$$->first_expr = $1.first;
$$->next = nullptr;
}
| LPAR LOCAL value_type_list RPAR func_body {
- $$ = new_func_field();
+ $$ = new FuncField();
$$->type = FuncFieldType::LocalTypes;
$$->types = $3;
$$->next = $5;
}
| LPAR LOCAL bind_var VALUE_TYPE RPAR func_body {
- $$ = new_func_field();
+ $$ = new FuncField();
$$->type = FuncFieldType::BoundLocal;
$$->bound_type.loc = @2;
$$->bound_type.name = $3;
@@ -766,15 +737,16 @@ func_info :
switch (field->type) {
case FuncFieldType::Exprs:
$$->first_expr = field->first_expr;
+ field->first_expr = nullptr;
break;
case FuncFieldType::ParamTypes:
case FuncFieldType::LocalTypes: {
- TypeVector* types = field->type == FuncFieldType::ParamTypes
- ? &$$->decl.sig.param_types
- : &$$->local_types;
- extend_types(types, &field->types);
- destroy_type_vector(&field->types);
+ TypeVector& types = field->type == FuncFieldType::ParamTypes
+ ? $$->decl.sig.param_types
+ : $$->local_types;
+ types.insert(types.end(), field->types->begin(),
+ field->types->end());
break;
}
@@ -790,19 +762,18 @@ func_info :
bindings = &$$->local_bindings;
}
- append_type_value(types, &field->bound_type.type);
- bindings->emplace(string_slice_to_string(field->bound_type.name),
- Binding(field->bound_type.loc, types->size - 1));
- destroy_string_slice(&field->bound_type.name);
+ types->push_back(field->bound_type.type);
+ bindings->emplace(
+ string_slice_to_string(field->bound_type.name),
+ Binding(field->bound_type.loc, types->size() - 1));
break;
}
case FuncFieldType::ResultTypes:
- $$->decl.sig.result_types = field->types;
+ $$->decl.sig.result_types = std::move(*field->types);
break;
}
- /* we steal memory from the func field, but not the linked list nodes */
delete field;
field = next;
}
@@ -810,32 +781,34 @@ func_info :
;
func :
LPAR FUNC bind_var_opt inline_export type_use func_info RPAR {
- WABT_ZERO_MEMORY($$);
- $$.func = $6;
- $$.func->decl.flags |= WABT_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE;
- $$.func->decl.type_var = $5;
- $$.func->name = $3;
- $$.export_ = $4;
+ $$ = new ExportedFunc();
+ $$->func.reset($6);
+ $$->func->decl.has_func_type = true;
+ $$->func->decl.type_var = $5;
+ $$->func->name = $3;
+ $$->export_ = std::move(*$4);
+ delete $4;
}
/* Duplicate above for empty inline_export_opt to avoid LR(1) conflict. */
| LPAR FUNC bind_var_opt type_use func_info RPAR {
- WABT_ZERO_MEMORY($$);
- $$.func = $5;
- $$.func->decl.flags |= WABT_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE;
- $$.func->decl.type_var = $4;
- $$.func->name = $3;
+ $$ = new ExportedFunc();
+ $$->func.reset($5);
+ $$->func->decl.has_func_type = true;
+ $$->func->decl.type_var = $4;
+ $$->func->name = $3;
}
| LPAR FUNC bind_var_opt inline_export func_info RPAR {
- WABT_ZERO_MEMORY($$);
- $$.func = $5;
- $$.func->name = $3;
- $$.export_ = $4;
+ $$ = new ExportedFunc();
+ $$->func.reset($5);
+ $$->func->name = $3;
+ $$->export_ = std::move(*$4);
+ delete $4;
}
/* Duplicate above for empty inline_export_opt to avoid LR(1) conflict. */
| LPAR FUNC bind_var_opt func_info RPAR {
- WABT_ZERO_MEMORY($$);
- $$.func = $4;
- $$.func->name = $3;
+ $$ = new ExportedFunc();
+ $$->func.reset($4);
+ $$->func->name = $3;
}
;
@@ -850,129 +823,138 @@ offset :
elem :
LPAR ELEM var offset var_list RPAR {
- WABT_ZERO_MEMORY($$);
- $$.table_var = $3;
- $$.offset = $4.first;
- $$.vars = $5;
+ $$ = new ElemSegment();
+ $$->table_var = $3;
+ $$->offset = $4.first;
+ $$->vars = std::move(*$5);
+ delete $5;
}
| LPAR ELEM offset var_list RPAR {
- WABT_ZERO_MEMORY($$);
- $$.table_var.loc = @2;
- $$.table_var.type = VarType::Index;
- $$.table_var.index = 0;
- $$.offset = $3.first;
- $$.vars = $4;
+ $$ = new ElemSegment();
+ $$->table_var.loc = @2;
+ $$->table_var.type = VarType::Index;
+ $$->table_var.index = 0;
+ $$->offset = $3.first;
+ $$->vars = std::move(*$4);
+ delete $4;
}
;
table :
LPAR TABLE bind_var_opt inline_export_opt table_sig RPAR {
- $$.table = $5;
- $$.table.name = $3;
- $$.has_elem_segment = false;
- $$.export_ = $4;
+ $$ = new ExportedTable();
+ $$->table.reset($5);
+ $$->table->name = $3;
+ $$->has_elem_segment = false;
+ $$->export_ = std::move(*$4);
+ delete $4;
}
| LPAR TABLE bind_var_opt inline_export_opt elem_type
LPAR ELEM var_list RPAR RPAR {
- Expr* expr = new_const_expr();
+ Expr* expr = Expr::CreateConst(Const(Const::I32(), 0));
expr->loc = @2;
- expr->const_.type = Type::I32;
- expr->const_.u32 = 0;
- WABT_ZERO_MEMORY($$);
- $$.table.name = $3;
- $$.table.elem_limits.initial = $8.size;
- $$.table.elem_limits.max = $8.size;
- $$.table.elem_limits.has_max = true;
- $$.has_elem_segment = true;
- $$.elem_segment.offset = expr;
- $$.elem_segment.vars = $8;
- $$.export_ = $4;
+ $$ = new ExportedTable();
+ $$->table.reset(new Table());
+ $$->table->name = $3;
+ $$->table->elem_limits.initial = $8->size();
+ $$->table->elem_limits.max = $8->size();
+ $$->table->elem_limits.has_max = true;
+ $$->has_elem_segment = true;
+ $$->elem_segment.reset(new ElemSegment());
+ $$->elem_segment->offset = expr;
+ $$->elem_segment->vars = std::move(*$8);
+ delete $8;
+ $$->export_ = std::move(*$4);
+ delete $4;
}
;
data :
LPAR DATA var offset text_list RPAR {
- WABT_ZERO_MEMORY($$);
- $$.memory_var = $3;
- $$.offset = $4.first;
- dup_text_list(&$5, &$$.data, &$$.size);
+ $$ = new DataSegment();
+ $$->memory_var = $3;
+ $$->offset = $4.first;
+ dup_text_list(&$5, &$$->data, &$$->size);
destroy_text_list(&$5);
}
| LPAR DATA offset text_list RPAR {
- WABT_ZERO_MEMORY($$);
- $$.memory_var.loc = @2;
- $$.memory_var.type = VarType::Index;
- $$.memory_var.index = 0;
- $$.offset = $3.first;
- dup_text_list(&$4, &$$.data, &$$.size);
+ $$ = new DataSegment();
+ $$->memory_var.loc = @2;
+ $$->memory_var.type = VarType::Index;
+ $$->memory_var.index = 0;
+ $$->offset = $3.first;
+ dup_text_list(&$4, &$$->data, &$$->size);
destroy_text_list(&$4);
}
;
memory :
LPAR MEMORY bind_var_opt inline_export_opt memory_sig RPAR {
- WABT_ZERO_MEMORY($$);
- $$.memory = $5;
- $$.memory.name = $3;
- $$.has_data_segment = false;
- $$.export_ = $4;
+ $$ = new ExportedMemory();
+ $$->memory.reset($5);
+ $$->memory->name = $3;
+ $$->has_data_segment = false;
+ $$->export_ = std::move(*$4);
+ delete $4;
}
| LPAR MEMORY bind_var_opt inline_export LPAR DATA text_list RPAR RPAR {
- Expr* expr = new_const_expr();
+ Expr* expr = Expr::CreateConst(Const(Const::I32(), 0));
expr->loc = @2;
- expr->const_.type = Type::I32;
- expr->const_.u32 = 0;
- WABT_ZERO_MEMORY($$);
- $$.has_data_segment = true;
- $$.data_segment.offset = expr;
- dup_text_list(&$7, &$$.data_segment.data, &$$.data_segment.size);
+ $$ = new ExportedMemory();
+ $$->has_data_segment = true;
+ $$->data_segment.reset(new DataSegment());
+ $$->data_segment->offset = expr;
+ dup_text_list(&$7, &$$->data_segment->data, &$$->data_segment->size);
destroy_text_list(&$7);
- uint32_t byte_size = WABT_ALIGN_UP_TO_PAGE($$.data_segment.size);
+ uint32_t byte_size = WABT_ALIGN_UP_TO_PAGE($$->data_segment->size);
uint32_t page_size = WABT_BYTES_TO_PAGES(byte_size);
- $$.memory.name = $3;
- $$.memory.page_limits.initial = page_size;
- $$.memory.page_limits.max = page_size;
- $$.memory.page_limits.has_max = true;
- $$.export_ = $4;
+ $$->memory.reset(new Memory());
+ $$->memory->name = $3;
+ $$->memory->page_limits.initial = page_size;
+ $$->memory->page_limits.max = page_size;
+ $$->memory->page_limits.has_max = true;
+ $$->export_ = std::move(*$4);
+ delete $4;
}
/* Duplicate above for empty inline_export_opt to avoid LR(1) conflict. */
| LPAR MEMORY bind_var_opt LPAR DATA text_list RPAR RPAR {
- Expr* expr = new_const_expr();
+ Expr* expr = Expr::CreateConst(Const(Const::I32(), 0));
expr->loc = @2;
- expr->const_.type = Type::I32;
- expr->const_.u32 = 0;
- WABT_ZERO_MEMORY($$);
- $$.has_data_segment = true;
- $$.data_segment.offset = expr;
- dup_text_list(&$6, &$$.data_segment.data, &$$.data_segment.size);
+ $$ = new ExportedMemory();
+ $$->has_data_segment = true;
+ $$->data_segment.reset(new DataSegment());
+ $$->data_segment->offset = expr;
+ dup_text_list(&$6, &$$->data_segment->data, &$$->data_segment->size);
destroy_text_list(&$6);
- uint32_t byte_size = WABT_ALIGN_UP_TO_PAGE($$.data_segment.size);
+ uint32_t byte_size = WABT_ALIGN_UP_TO_PAGE($$->data_segment->size);
uint32_t page_size = WABT_BYTES_TO_PAGES(byte_size);
- $$.memory.name = $3;
- $$.memory.page_limits.initial = page_size;
- $$.memory.page_limits.max = page_size;
- $$.memory.page_limits.has_max = true;
- $$.export_.has_export = false;
+ $$->memory.reset(new Memory());
+ $$->memory->name = $3;
+ $$->memory->page_limits.initial = page_size;
+ $$->memory->page_limits.max = page_size;
+ $$->memory->page_limits.has_max = true;
+ $$->export_.has_export = false;
}
;
global :
LPAR GLOBAL bind_var_opt inline_export global_type const_expr RPAR {
- WABT_ZERO_MEMORY($$);
- $$.global = $5;
- $$.global.name = $3;
- $$.global.init_expr = $6.first;
- $$.export_ = $4;
+ $$ = new ExportedGlobal();
+ $$->global.reset($5);
+ $$->global->name = $3;
+ $$->global->init_expr = $6.first;
+ $$->export_ = std::move(*$4);
+ delete $4;
}
| LPAR GLOBAL bind_var_opt global_type const_expr RPAR {
- WABT_ZERO_MEMORY($$);
- $$.global = $4;
- $$.global.name = $3;
- $$.global.init_expr = $5.first;
- $$.export_.has_export = false;
+ $$ = new ExportedGlobal();
+ $$->global.reset($4);
+ $$->global->name = $3;
+ $$->global->init_expr = $5.first;
+ $$->export_.has_export = false;
}
;
@@ -981,37 +963,38 @@ global :
import_kind :
LPAR FUNC bind_var_opt type_use RPAR {
- $$ = new_import();
+ $$ = new Import();
$$->kind = ExternalKind::Func;
$$->func = new Func();
$$->func->name = $3;
- $$->func->decl.flags = WABT_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE;
+ $$->func->decl.has_func_type = true;
$$->func->decl.type_var = $4;
}
| LPAR FUNC bind_var_opt func_sig RPAR {
- $$ = new_import();
+ $$ = new Import();
$$->kind = ExternalKind::Func;
$$->func = new Func();
$$->func->name = $3;
- $$->func->decl.sig = $4;
+ $$->func->decl.sig = std::move(*$4);
+ delete $4;
}
| LPAR TABLE bind_var_opt table_sig RPAR {
- $$ = new_import();
+ $$ = new Import();
$$->kind = ExternalKind::Table;
$$->table = $4;
- $$->table.name = $3;
+ $$->table->name = $3;
}
| LPAR MEMORY bind_var_opt memory_sig RPAR {
- $$ = new_import();
+ $$ = new Import();
$$->kind = ExternalKind::Memory;
$$->memory = $4;
- $$->memory.name = $3;
+ $$->memory->name = $3;
}
| LPAR GLOBAL bind_var_opt global_type RPAR {
- $$ = new_import();
+ $$ = new Import();
$$->kind = ExternalKind::Global;
$$->global = $4;
- $$->global.name = $3;
+ $$->global->name = $3;
}
;
import :
@@ -1025,7 +1008,7 @@ import :
$$->kind = ExternalKind::Func;
$$->func = new Func();
$$->func->name = $3;
- $$->func->decl.flags = WABT_FUNC_DECLARATION_FLAG_HAS_FUNC_TYPE;
+ $$->func->decl.has_func_type = true;
$$->func->decl.type_var = $5;
}
| LPAR FUNC bind_var_opt inline_import func_sig RPAR {
@@ -1033,31 +1016,32 @@ import :
$$->kind = ExternalKind::Func;
$$->func = new Func();
$$->func->name = $3;
- $$->func->decl.sig = $5;
+ $$->func->decl.sig = std::move(*$5);
+ delete $5;
}
| LPAR TABLE bind_var_opt inline_import table_sig RPAR {
$$ = $4;
$$->kind = ExternalKind::Table;
$$->table = $5;
- $$->table.name = $3;
+ $$->table->name = $3;
}
| LPAR MEMORY bind_var_opt inline_import memory_sig RPAR {
$$ = $4;
$$->kind = ExternalKind::Memory;
$$->memory = $5;
- $$->memory.name = $3;
+ $$->memory->name = $3;
}
| LPAR GLOBAL bind_var_opt inline_import global_type RPAR {
$$ = $4;
$$->kind = ExternalKind::Global;
$$->global = $5;
- $$->global.name = $3;
+ $$->global->name = $3;
}
;
inline_import :
LPAR IMPORT quoted_text quoted_text RPAR {
- $$ = new_import();
+ $$ = new Import();
$$->module_name = $3;
$$->field_name = $4;
}
@@ -1065,45 +1049,46 @@ inline_import :
export_kind :
LPAR FUNC var RPAR {
- WABT_ZERO_MEMORY($$);
- $$.kind = ExternalKind::Func;
- $$.var = $3;
+ $$ = new Export();
+ $$->kind = ExternalKind::Func;
+ $$->var = $3;
}
| LPAR TABLE var RPAR {
- WABT_ZERO_MEMORY($$);
- $$.kind = ExternalKind::Table;
- $$.var = $3;
+ $$ = new Export();
+ $$->kind = ExternalKind::Table;
+ $$->var = $3;
}
| LPAR MEMORY var RPAR {
- WABT_ZERO_MEMORY($$);
- $$.kind = ExternalKind::Memory;
- $$.var = $3;
+ $$ = new Export();
+ $$->kind = ExternalKind::Memory;
+ $$->var = $3;
}
| LPAR GLOBAL var RPAR {
- WABT_ZERO_MEMORY($$);
- $$.kind = ExternalKind::Global;
- $$.var = $3;
+ $$ = new Export();
+ $$->kind = ExternalKind::Global;
+ $$->var = $3;
}
;
export :
LPAR EXPORT quoted_text export_kind RPAR {
$$ = $4;
- $$.name = $3;
+ $$->name = $3;
}
;
inline_export_opt :
/* empty */ {
- WABT_ZERO_MEMORY($$);
- $$.has_export = false;
+ $$ = new OptionalExport();
+ $$->has_export = false;
}
| inline_export
;
inline_export :
LPAR EXPORT quoted_text RPAR {
- WABT_ZERO_MEMORY($$);
- $$.has_export = true;
- $$.export_.name = $3;
+ $$ = new OptionalExport();
+ $$->has_export = true;
+ $$->export_.reset(new Export());
+ $$->export_->name = $3;
}
;
@@ -1112,12 +1097,15 @@ inline_export :
type_def :
LPAR TYPE func_type RPAR {
- WABT_ZERO_MEMORY($$);
- $$.sig = $3;
+ $$ = new FuncType();
+ $$->sig = std::move(*$3);
+ delete $3;
}
| LPAR TYPE bind_var func_type RPAR {
- $$.name = $3;
- $$.sig = $4;
+ $$ = new FuncType();
+ $$->name = $3;
+ $$->sig = std::move(*$4);
+ delete $4;
}
;
@@ -1127,79 +1115,79 @@ start :
module_fields :
/* empty */ {
- $$ = new_module();
+ $$ = new Module();
}
| module_fields type_def {
$$ = $1;
ModuleField* field;
APPEND_FIELD_TO_LIST($$, field, FuncType, func_type, @2, $2);
- APPEND_ITEM_TO_VECTOR($$, FuncType, func_type, func_types,
- &field->func_type);
- INSERT_BINDING($$, func_type, func_types, @2, $2.name);
+ APPEND_ITEM_TO_VECTOR($$, func_types, field->func_type);
+ INSERT_BINDING($$, func_type, func_types, @2, $2->name);
}
| module_fields global {
$$ = $1;
ModuleField* field;
- APPEND_FIELD_TO_LIST($$, field, Global, global, @2, $2.global);
- APPEND_ITEM_TO_VECTOR($$, Global, global, globals, &field->global);
- INSERT_BINDING($$, global, globals, @2, $2.global.name);
- APPEND_INLINE_EXPORT($$, Global, @2, $2, $$->globals.size - 1);
+ APPEND_FIELD_TO_LIST($$, field, Global, global, @2, $2->global.release());
+ APPEND_ITEM_TO_VECTOR($$, globals, field->global);
+ INSERT_BINDING($$, global, globals, @2, field->global->name);
+ APPEND_INLINE_EXPORT($$, Global, @2, $2, $$->globals.size() - 1);
+ delete $2;
}
| module_fields table {
$$ = $1;
ModuleField* field;
- APPEND_FIELD_TO_LIST($$, field, Table, table, @2, $2.table);
- APPEND_ITEM_TO_VECTOR($$, Table, table, tables, &field->table);
- INSERT_BINDING($$, table, tables, @2, $2.table.name);
- APPEND_INLINE_EXPORT($$, Table, @2, $2, $$->tables.size - 1);
+ APPEND_FIELD_TO_LIST($$, field, Table, table, @2, $2->table.release());
+ APPEND_ITEM_TO_VECTOR($$, tables, field->table);
+ INSERT_BINDING($$, table, tables, @2, field->table->name);
+ APPEND_INLINE_EXPORT($$, Table, @2, $2, $$->tables.size() - 1);
- if ($2.has_elem_segment) {
+ if ($2->has_elem_segment) {
ModuleField* elem_segment_field;
APPEND_FIELD_TO_LIST($$, elem_segment_field, ElemSegment, elem_segment,
- @2, $2.elem_segment);
- APPEND_ITEM_TO_VECTOR($$, ElemSegment, elem_segment, elem_segments,
- &elem_segment_field->elem_segment);
+ @2, $2->elem_segment.release());
+ APPEND_ITEM_TO_VECTOR($$, elem_segments,
+ elem_segment_field->elem_segment);
}
-
+ delete $2;
}
| module_fields memory {
$$ = $1;
ModuleField* field;
- APPEND_FIELD_TO_LIST($$, field, Memory, memory, @2, $2.memory);
- APPEND_ITEM_TO_VECTOR($$, Memory, memory, memories, &field->memory);
- INSERT_BINDING($$, memory, memories, @2, $2.memory.name);
- APPEND_INLINE_EXPORT($$, Memory, @2, $2, $$->memories.size - 1);
+ APPEND_FIELD_TO_LIST($$, field, Memory, memory, @2, $2->memory.release());
+ APPEND_ITEM_TO_VECTOR($$, memories, field->memory);
+ INSERT_BINDING($$, memory, memories, @2, field->memory->name);
+ APPEND_INLINE_EXPORT($$, Memory, @2, $2, $$->memories.size() - 1);
- if ($2.has_data_segment) {
+ if ($2->has_data_segment) {
ModuleField* data_segment_field;
APPEND_FIELD_TO_LIST($$, data_segment_field, DataSegment, data_segment,
- @2, $2.data_segment);
- APPEND_ITEM_TO_VECTOR($$, DataSegment, data_segment, data_segments,
- &data_segment_field->data_segment);
+ @2, $2->data_segment.release());
+ APPEND_ITEM_TO_VECTOR($$, data_segments,
+ data_segment_field->data_segment);
}
+ delete $2;
}
| module_fields func {
$$ = $1;
ModuleField* field;
- APPEND_FIELD_TO_LIST($$, field, Func, func, @2, $2.func);
+ APPEND_FIELD_TO_LIST($$, field, Func, func, @2, $2->func.release());
append_implicit_func_declaration(&@2, $$, &field->func->decl);
- APPEND_ITEM_TO_VECTOR($$, Func, func, funcs, field->func);
- INSERT_BINDING($$, func, funcs, @2, $2.func->name);
- APPEND_INLINE_EXPORT($$, Func, @2, $2, $$->funcs.size - 1);
+ APPEND_ITEM_TO_VECTOR($$, funcs, field->func);
+ INSERT_BINDING($$, func, funcs, @2, field->func->name);
+ APPEND_INLINE_EXPORT($$, Func, @2, $2, $$->funcs.size() - 1);
+ delete $2;
}
| module_fields elem {
$$ = $1;
ModuleField* field;
APPEND_FIELD_TO_LIST($$, field, ElemSegment, elem_segment, @2, $2);
- APPEND_ITEM_TO_VECTOR($$, ElemSegment, elem_segment, elem_segments,
- &field->elem_segment);
+ APPEND_ITEM_TO_VECTOR($$, elem_segments, field->elem_segment);
}
| module_fields data {
$$ = $1;
ModuleField* field;
APPEND_FIELD_TO_LIST($$, field, DataSegment, data_segment, @2, $2);
- APPEND_ITEM_TO_VECTOR($$, DataSegment, data_segment, data_segments,
- &field->data_segment);
+ APPEND_ITEM_TO_VECTOR($$, data_segments, field->data_segment);
}
| module_fields start {
$$ = $1;
@@ -1218,92 +1206,91 @@ module_fields :
switch ($2->kind) {
case ExternalKind::Func:
append_implicit_func_declaration(&@2, $$, &field->import->func->decl);
- APPEND_ITEM_TO_VECTOR($$, Func, func, funcs, field->import->func);
+ APPEND_ITEM_TO_VECTOR($$, funcs, field->import->func);
INSERT_BINDING($$, func, funcs, @2, field->import->func->name);
$$->num_func_imports++;
break;
case ExternalKind::Table:
- APPEND_ITEM_TO_VECTOR($$, Table, table, tables,
- &field->import->table);
- INSERT_BINDING($$, table, tables, @2, field->import->table.name);
+ APPEND_ITEM_TO_VECTOR($$, tables, field->import->table);
+ INSERT_BINDING($$, table, tables, @2, field->import->table->name);
$$->num_table_imports++;
break;
case ExternalKind::Memory:
- APPEND_ITEM_TO_VECTOR($$, Memory, memory, memories,
- &field->import->memory);
- INSERT_BINDING($$, memory, memories, @2, field->import->memory.name);
+ APPEND_ITEM_TO_VECTOR($$, memories, field->import->memory);
+ INSERT_BINDING($$, memory, memories, @2, field->import->memory->name);
$$->num_memory_imports++;
break;
case ExternalKind::Global:
- APPEND_ITEM_TO_VECTOR($$, Global, global, globals,
- &field->import->global);
- INSERT_BINDING($$, global, globals, @2, field->import->global.name);
+ APPEND_ITEM_TO_VECTOR($$, globals, field->import->global);
+ INSERT_BINDING($$, global, globals, @2, field->import->global->name);
$$->num_global_imports++;
break;
}
- APPEND_ITEM_TO_VECTOR($$, Import, import, imports, field->import);
+ APPEND_ITEM_TO_VECTOR($$, imports, field->import);
}
| module_fields export {
$$ = $1;
ModuleField* field;
APPEND_FIELD_TO_LIST($$, field, Export, export_, @2, $2);
- APPEND_ITEM_TO_VECTOR($$, Export, export, exports, &field->export_);
- INSERT_BINDING($$, export, exports, @2, $2.name);
+ APPEND_ITEM_TO_VECTOR($$, exports, field->export_);
+ INSERT_BINDING($$, export, exports, @2, field->export_->name);
}
;
raw_module :
LPAR MODULE bind_var_opt module_fields RPAR {
- $$.type = RawModuleType::Text;
- $$.text = $4;
- $$.text->name = $3;
- $$.text->loc = @2;
+ $$ = new RawModule();
+ $$->type = RawModuleType::Text;
+ $$->text = $4;
+ $$->text->name = $3;
+ $$->text->loc = @2;
/* resolve func type variables where the signature was not specified
* explicitly */
- for (size_t i = 0; i < $4->funcs.size; ++i) {
- Func* func = $4->funcs.data[i];
+ for (Func* func: $4->funcs) {
if (decl_has_func_type(&func->decl) &&
is_empty_signature(&func->decl.sig)) {
FuncType* func_type =
get_func_type_by_var($4, &func->decl.type_var);
if (func_type) {
func->decl.sig = func_type->sig;
- func->decl.flags |= WABT_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE;
}
}
}
}
| LPAR MODULE bind_var_opt non_empty_text_list RPAR {
- $$.type = RawModuleType::Binary;
- $$.binary.name = $3;
- $$.binary.loc = @2;
- dup_text_list(&$4, &$$.binary.data, &$$.binary.size);
+ $$ = new RawModule();
+ $$->type = RawModuleType::Binary;
+ $$->binary.name = $3;
+ $$->binary.loc = @2;
+ dup_text_list(&$4, &$$->binary.data, &$$->binary.size);
destroy_text_list(&$4);
}
;
module :
raw_module {
- if ($1.type == RawModuleType::Text) {
- $$ = $1.text;
+ if ($1->type == RawModuleType::Text) {
+ $$ = $1->text;
+ $1->text = nullptr;
} else {
- assert($1.type == RawModuleType::Binary);
- $$ = new_module();
+ assert($1->type == RawModuleType::Binary);
+ $$ = new Module();
ReadBinaryOptions options = WABT_READ_BINARY_OPTIONS_DEFAULT;
BinaryErrorCallbackData user_data;
- user_data.loc = &$1.binary.loc;
+ user_data.loc = &$1->binary.loc;
user_data.lexer = lexer;
user_data.parser = parser;
BinaryErrorHandler error_handler;
error_handler.on_error = on_read_binary_error;
error_handler.user_data = &user_data;
- read_binary_ast($1.binary.data, $1.binary.size, &options,
- &error_handler, $$);
- delete [] $1.binary.data;
- $$->name = $1.binary.name;
- $$->loc = $1.binary.loc;
+ read_binary_ast($1->binary.data, $1->binary.size, &options,
+ &error_handler, $$);
+ $$->name = $1->binary.name;
+ $$->loc = $1->binary.loc;
+ WABT_ZERO_MEMORY($1->binary.name);
}
+ delete $1;
}
;
@@ -1324,66 +1311,68 @@ script_var_opt :
action :
LPAR INVOKE script_var_opt quoted_text const_list RPAR {
- WABT_ZERO_MEMORY($$);
- $$.loc = @2;
- $$.module_var = $3;
- $$.type = ActionType::Invoke;
- $$.invoke.name = $4;
- $$.invoke.args = $5;
+ $$ = new Action();
+ $$->loc = @2;
+ $$->module_var = $3;
+ $$->type = ActionType::Invoke;
+ $$->name = $4;
+ $$->invoke = new ActionInvoke();
+ $$->invoke->args = std::move(*$5);
+ delete $5;
}
| LPAR GET script_var_opt quoted_text RPAR {
- WABT_ZERO_MEMORY($$);
- $$.loc = @2;
- $$.module_var = $3;
- $$.type = ActionType::Get;
- $$.invoke.name = $4;
+ $$ = new Action();
+ $$->loc = @2;
+ $$->module_var = $3;
+ $$->type = ActionType::Get;
+ $$->name = $4;
}
;
assertion :
LPAR ASSERT_MALFORMED raw_module quoted_text RPAR {
- $$ = new_command();
+ $$ = new Command();
$$->type = CommandType::AssertMalformed;
$$->assert_malformed.module = $3;
$$->assert_malformed.text = $4;
}
| LPAR ASSERT_INVALID raw_module quoted_text RPAR {
- $$ = new_command();
+ $$ = new Command();
$$->type = CommandType::AssertInvalid;
$$->assert_invalid.module = $3;
$$->assert_invalid.text = $4;
}
| LPAR ASSERT_UNLINKABLE raw_module quoted_text RPAR {
- $$ = new_command();
+ $$ = new Command();
$$->type = CommandType::AssertUnlinkable;
$$->assert_unlinkable.module = $3;
$$->assert_unlinkable.text = $4;
}
| LPAR ASSERT_TRAP raw_module quoted_text RPAR {
- $$ = new_command();
+ $$ = new Command();
$$->type = CommandType::AssertUninstantiable;
$$->assert_uninstantiable.module = $3;
$$->assert_uninstantiable.text = $4;
}
| LPAR ASSERT_RETURN action const_list RPAR {
- $$ = new_command();
+ $$ = new Command();
$$->type = CommandType::AssertReturn;
$$->assert_return.action = $3;
$$->assert_return.expected = $4;
}
| LPAR ASSERT_RETURN_NAN action RPAR {
- $$ = new_command();
+ $$ = new Command();
$$->type = CommandType::AssertReturnNan;
$$->assert_return_nan.action = $3;
}
| LPAR ASSERT_TRAP action quoted_text RPAR {
- $$ = new_command();
+ $$ = new Command();
$$->type = CommandType::AssertTrap;
$$->assert_trap.action = $3;
$$->assert_trap.text = $4;
}
| LPAR ASSERT_EXHAUSTION action quoted_text RPAR {
- $$ = new_command();
+ $$ = new Command();
$$->type = CommandType::AssertExhaustion;
$$->assert_trap.action = $3;
$$->assert_trap.text = $4;
@@ -1392,18 +1381,18 @@ assertion :
cmd :
action {
- $$ = new_command();
+ $$ = new Command();
$$->type = CommandType::Action;
$$->action = $1;
}
| assertion
| module {
- $$ = new_command();
+ $$ = new Command();
$$->type = CommandType::Module;
$$->module = $1;
}
| LPAR REGISTER quoted_text script_var_opt RPAR {
- $$ = new_command();
+ $$ = new Command();
$$->type = CommandType::Register;
$$->register_.module_name = $3;
$$->register_.var = $4;
@@ -1411,11 +1400,10 @@ cmd :
}
;
cmd_list :
- /* empty */ { WABT_ZERO_MEMORY($$); }
+ /* empty */ { $$ = new CommandPtrVector(); }
| cmd_list cmd {
$$ = $1;
- append_command_value(&$$, $2);
- delete $2;
+ $$->emplace_back($2);
}
;
@@ -1432,28 +1420,29 @@ const :
}
;
const_list :
- /* empty */ { WABT_ZERO_MEMORY($$); }
+ /* empty */ { $$ = new ConstVector(); }
| const_list const {
$$ = $1;
- append_const_value(&$$, &$2);
+ $$->push_back($2);
}
;
script :
cmd_list {
$$ = new Script();
- $$->commands = $1;
+ $$->commands = std::move(*$1);
+ delete $1;
int last_module_index = -1;
- for (size_t i = 0; i < $$->commands.size; ++i) {
- Command* command = &$$->commands.data[i];
+ for (size_t i = 0; i < $$->commands.size(); ++i) {
+ Command& command = *$$->commands[i].get();
Var* module_var = nullptr;
- switch (command->type) {
+ switch (command.type) {
case CommandType::Module: {
last_module_index = i;
/* Wire up module name bindings. */
- Module* module = command->module;
+ Module* module = command.module;
if (module->name.length == 0)
continue;
@@ -1463,20 +1452,20 @@ script :
}
case CommandType::AssertReturn:
- module_var = &command->assert_return.action.module_var;
+ module_var = &command.assert_return.action->module_var;
goto has_module_var;
case CommandType::AssertReturnNan:
- module_var = &command->assert_return_nan.action.module_var;
+ module_var = &command.assert_return_nan.action->module_var;
goto has_module_var;
case CommandType::AssertTrap:
case CommandType::AssertExhaustion:
- module_var = &command->assert_trap.action.module_var;
+ module_var = &command.assert_trap.action->module_var;
goto has_module_var;
case CommandType::Action:
- module_var = &command->action.module_var;
+ module_var = &command.action->module_var;
goto has_module_var;
case CommandType::Register:
- module_var = &command->register_.var;
+ module_var = &command.register_.var;
goto has_module_var;
has_module_var: {
@@ -1635,8 +1624,8 @@ void dup_text_list(TextList* text_list, char** out_data, size_t* out_size) {
*out_size = dest - result;
}
-bool is_empty_signature(FuncSignature* sig) {
- return sig->result_types.size == 0 && sig->param_types.size == 0;
+bool is_empty_signature(const FuncSignature* sig) {
+ return sig->result_types.empty() && sig->param_types.empty();
}
void append_implicit_func_declaration(Location* loc,
@@ -1649,13 +1638,8 @@ void append_implicit_func_declaration(Location* loc,
if (sig_index == -1) {
append_implicit_func_type(loc, module, &decl->sig);
} else {
- /* signature already exists, share that one and destroy this one */
- destroy_func_signature(&decl->sig);
- FuncSignature* sig = &module->func_types.data[sig_index]->sig;
- decl->sig = *sig;
+ decl->sig = module->func_types[sig_index]->sig;
}
-
- decl->flags |= WABT_FUNC_DECLARATION_FLAG_SHARED_SIGNATURE;
}
Result parse_ast(AstLexer* lexer, Script** out_script,