Skip to content

Commit b0703c7

Browse files
committed
Correct the case of initial value at parse time for set and enums
1 parent 5f49c52 commit b0703c7

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

src/fast_type_gen/cpp_gen.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,8 @@ void cpp_gen::visit(const mfast::enum_field_instruction *inst, void *pIndex) {
635635

636636
std::string context = gen_op_context(inst->name(), inst->op_context());
637637

638+
const mfast::value_storage &init_value = inst->initial_value();
639+
638640
out_ << "const static " << instruction_type.str() << "\n"
639641
<< instruction_variable_name << "(\n"
640642
<< " " << get_operator_name(inst) << ",\n"
@@ -643,8 +645,12 @@ void cpp_gen::visit(const mfast::enum_field_instruction *inst, void *pIndex) {
643645
<< " \"" << inst->name() << "\", // name\n"
644646
<< " \"" << inst->ns() << "\", // ns\n"
645647
<< " " << context << ", // opContext\n"
646-
<< " int_value_storage<uint64_t>("
647-
<< inst->initial_value().get<uint64_t>() << "), // initial_value\n"
648+
<< " int_value_storage<uint64_t>(";
649+
650+
if (!init_value.is_empty())
651+
out_ << init_value.get<uint64_t>();
652+
653+
out_ << "), // initial_value\n"
648654
<< " " << elements_variable_name.str() << ", // element names\n"
649655
<< " " << values_variable_name << ", // element values\n"
650656
<< " " << num_elements_name.str() << ",// num elements\n"
@@ -702,6 +708,9 @@ void cpp_gen::visit(const mfast::set_field_instruction *inst, void *pIndex)
702708
out_ << "};\n";
703709
}
704710
std::string context = gen_op_context(inst->name(), inst->op_context());
711+
712+
const mfast::value_storage &init_value = inst->initial_value();
713+
705714
out_ << "const static " << instruction_type.str() << "\n"
706715
<< instruction_variable_name << "(\n"
707716
<< " " << get_operator_name(inst) << ",\n"
@@ -710,8 +719,12 @@ void cpp_gen::visit(const mfast::set_field_instruction *inst, void *pIndex)
710719
<< " \"" << inst->name() << "\", // name\n"
711720
<< " \"" << inst->ns() << "\", // ns\n"
712721
<< " " << context << ", // opContext\n"
713-
<< " int_value_storage<uint64_t>("
714-
<< inst->initial_value().get<uint64_t>() << "), // initial_value\n"
722+
<< " int_value_storage<uint64_t>(";
723+
724+
if (!init_value.is_empty())
725+
out_ << init_value.get<uint64_t>();
726+
727+
out_ << "), // initial_value\n"
715728
<< " " << elements_variable_name.str() << ", // element names\n"
716729
<< " " << num_elements_name.str() << ",// num elements\n"
717730
<< " nullptr, // ref_instruction\n"

src/mfast/xml_parser/templates_builder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ templates_builder::templates_builder(dynamic_templates_description *definition,
3535
instructions_view_t(nullptr, 0), nullptr, nullptr,
3636
&length_instruction_prototype, "", "", cpp_ns_),
3737
enum_field_instruction_prototype_(operator_none, presence_mandatory, 0,
38-
nullptr, "", nullptr, 0, nullptr,
38+
nullptr, "", nullptr, int_value_storage<uint64_t>(), nullptr,
3939
nullptr, 0, nullptr, cpp_ns_),
4040
set_field_instruction_prototype_(operator_none, presence_mandatory, 0,
41-
nullptr, "", nullptr, 0, nullptr,
41+
nullptr, "", nullptr, int_value_storage<uint64_t>(), nullptr,
4242
0, nullptr, cpp_ns_) {
4343
static const int32_field_instruction int32_field_instruction_prototype(
4444
operator_none, presence_mandatory, 0, nullptr, "", nullptr,

0 commit comments

Comments
 (0)