@@ -25,11 +25,13 @@ std::string get_properties_type(const Instruction *inst) {
2525using namespace mfast ;
2626struct ext_cref_type_getter : mfast::field_instruction_visitor {
2727 std::stringstream out_;
28+ bool is_group_type_ = false ;
2829
2930public:
3031 ext_cref_type_getter () {}
3132
3233 std::string get () { return out_.str (); }
34+ bool group_type () { return is_group_type_; }
3335
3436 virtual void visit (const int32_field_instruction *inst, void *) override {
3537 out_ << " ext_cref<int32_cref, " << get_operator_tag (inst) << " , "
@@ -83,6 +85,7 @@ struct ext_cref_type_getter : mfast::field_instruction_visitor {
8385 virtual void visit (const group_field_instruction *inst, void *) override {
8486 out_ << " ext_cref< " << codegen_base::cpp_name (inst)
8587 << " _cref, group_type_tag, " << get_properties_type (inst) << " >" ;
88+ is_group_type_ = true ;
8689 }
8790
8891 virtual void visit (const sequence_field_instruction *inst, void *) override ;
@@ -132,6 +135,12 @@ std::string get_ext_cref_type(const field_instruction *inst) {
132135 return getter.get ();
133136}
134137
138+ bool is_group_type (const field_instruction *inst) {
139+ ext_cref_type_getter getter;
140+ inst->accept (getter, nullptr );
141+ return getter.group_type ();
142+ }
143+
135144void ext_cref_type_getter::visit (const sequence_field_instruction *inst,
136145 void *) {
137146 const uint32_field_instruction *length_inst = inst->length_instruction ();
@@ -473,9 +482,17 @@ void inl_gen::visit(const mfast::group_field_instruction *inst, void *pIndex) {
473482
474483 for (std::size_t i = 0 ; i < inst->subinstructions ().size (); ++i) {
475484 const field_instruction *subinst = inst->subinstructions ()[i];
476- ;
477- out_ << " visitor.visit(" << get_ext_cref_type (subinst) << " ((*this)["
478- << i << " ]) );\n " ;
485+
486+ if (is_group_type (subinst) && subinst->optional ())
487+ {
488+ out_ << " {\n "
489+ << " " << get_ext_cref_type (subinst) << " ext_cref_group((*this)[" << i << " ]);\n "
490+ << " ext_cref_group.set_group_present(this->field_storage(" << i << " )->is_present());\n "
491+ << " visitor.visit(ext_cref_group);\n "
492+ << " }\n " ;
493+ }
494+ else
495+ out_ << " visitor.visit(" << get_ext_cref_type (subinst) << " ((*this)[" << i << " ]) );\n " ;
479496 }
480497
481498 out_ << " }\n\n " ;
@@ -508,6 +525,7 @@ void inl_gen::visit(const mfast::group_field_instruction *inst, void *pIndex) {
508525
509526 for (std::size_t i = 0 ; i < inst->subinstructions ().size (); ++i) {
510527 const field_instruction *subinst = inst->subinstructions ()[i];
528+
511529 out_ << " visitor.visit(" << get_ext_mref_type (subinst) << " ((*this)["
512530 << i << " ]) );\n " ;
513531 }
@@ -662,7 +680,7 @@ void inl_gen::visit(const mfast::sequence_field_instruction *inst,
662680
663681 for (std::size_t i = 0 ; i < inst->subinstructions ().size (); ++i) {
664682 const field_instruction *subinst = inst->subinstructions ()[i];
665- ;
683+
666684 out_ << " visitor.visit(" << get_ext_cref_type (subinst) << " ((*this)["
667685 << i << " ]) );\n " ;
668686 }
@@ -677,7 +695,7 @@ void inl_gen::visit(const mfast::sequence_field_instruction *inst,
677695
678696 for (std::size_t i = 0 ; i < inst->subinstructions ().size (); ++i) {
679697 const field_instruction *subinst = inst->subinstructions ()[i];
680- ;
698+
681699 out_ << " visitor.visit(" << get_ext_mref_type (subinst) << " ((*this)["
682700 << i << " ]) );\n " ;
683701 }
@@ -791,9 +809,17 @@ void inl_gen::visit(const mfast::template_instruction *inst, void *) {
791809
792810 for (std::size_t i = 0 ; i < inst->subinstructions ().size (); ++i) {
793811 const field_instruction *subinst = inst->subinstructions ()[i];
794- ;
795- out_ << " visitor.visit(" << get_ext_cref_type (subinst) << " ((*this)["
796- << i << " ]) );\n " ;
812+
813+ if (is_group_type (subinst) && subinst->optional ())
814+ {
815+ out_ << " {\n "
816+ << " " << get_ext_cref_type (subinst) << " ext_cref_group((*this)[" << i << " ]);\n "
817+ << " ext_cref_group.set_group_present(this->field_storage(" << i << " )->is_present());\n "
818+ << " visitor.visit(ext_cref_group);\n "
819+ << " }\n " ;
820+ }
821+ else
822+ out_ << " visitor.visit(" << get_ext_cref_type (subinst) << " ((*this)[" << i << " ]) );\n " ;
797823 }
798824
799825 out_ << " }\n\n " ;
@@ -842,7 +868,7 @@ void inl_gen::visit(const mfast::template_instruction *inst, void *) {
842868
843869 for (std::size_t i = 0 ; i < inst->subinstructions ().size (); ++i) {
844870 const field_instruction *subinst = inst->subinstructions ()[i];
845- ;
871+
846872 out_ << " visitor.visit(" << get_ext_mref_type (subinst) << " ((*this)["
847873 << i << " ]) );\n " ;
848874 }
0 commit comments