+}
+
+void CPPFile::align_type(Symbol *sym)
+{
+ file << '\n'
+ << indent << "ctx.buf.align_to(__alignof__(";
+ cpp_output_name(file, sym);
+ file << "));\n";
+}
+
+void CPPFile::grow_buf()
+{
+ file << indent << "ptr = ctx.buf.grow_by(len);\n";
+}
+
+void CPPFile::marshall_members(Struct *sym)
+{
+ for (Struct::entries_iterator i = sym->entries_begin();
+ i != sym->entries_end(); ++i)
+ {
+ Datum *member = *i;
+
+ if (member->type)
+ member->type->output_lang(this, trav_marshall, member);
+ else
+ output_marshall(member->def.basictype, member);
+ }
+}
+
+void CPPFile::output_marshall_array(Datum *d)
+{
+ file << '\n'
+ << indent << "ctx.buf.align_to(__alignof__(*data->" << **d->name << ".ptr));\n"
+ << indent << "len = data->" << **d->name
+ << ".count * sizeof(*data->" << **d->name << ".ptr);\n";
+
+ grow_buf();
+
+ file << indent << "memcpy(ptr, data->" << **d->name << ".ptr, len);\n";
+}
+
+void CPPFile::output_marshall_method(Struct *sym)
+{
+ file << indent << "__attribute__((weak)) __attribute__((unused))\n"
+ << indent << "void *_marshall(::System::RunTime::MarshCtx &ctx, ";
+ cpp_output_name(file, sym);
+ file << " *data, ";
+ cpp_output_name(file, sym);
+ file << " **link)\n"
+ << indent << "{\n";
+
+ indent.indent_level++;
+
+ file << indent << "__attribute__((unused)) ";
+ cpp_output_name(file, sym);
+ file << " *sptr;\n"
+ << indent << "void *ptr;\n"
+ << indent << "size_t len;\n"
+ << indent << "__attribute__((unused)) size_t i = 0;\n";
+
+ align_type(sym);
+ file << indent << "*link = (";
+ cpp_output_name(file, sym);
+ file << " *)ctx.buf.count;\n";
+ file << indent << "len = sizeof(*data);\n";
+ grow_buf();
+
+ file << indent << "memcpy(ptr, data, len);\n"
+ << indent << "sptr = (";
+ cpp_output_name(file, sym);
+ file << " *)ptr;\n";
+
+ marshall_members(sym);
+ indent.indent_level--;
+
+ file << indent << "\treturn 0;\n"
+ << indent << "}\n\n";
+}
+
+void CPPFile::output_marshall_inline_method(Struct *sym)
+{
+ file << indent << "__attribute__((weak)) __attribute__((unused))\n"
+ << indent << "void *_marshall_inline(::System::RunTime::MarshCtx &ctx, ";
+ cpp_output_name(file, sym);
+ file << " *data, ";
+ cpp_output_name(file, sym);
+ file << " *sptr)\n"
+ << indent << "{\n";
+
+ indent.indent_level++;
+
+ file << indent << "__attribute__((unused)) void *ptr;\n"
+ << indent << "__attribute__((unused)) size_t len;\n"
+ << indent << "__attribute__((unused)) size_t i = 0;\n";
+
+ marshall_members(sym);
+ indent.indent_level--;
+
+ file << indent << "\treturn 0;\n"
+ << indent << "}\n";
+}
+
+void CPPFile::output_marshall(Struct *sym, Datum *d)
+{
+ bool array = d->is_array(), inl = d->is_inline();
+ const char *index = "";
+
+ file << '\n';
+
+ if (array) {
+ file << indent << "for (size_t i = 0; i < ";
+
+ if (inl)
+ file << d->array->cons[0].con.ucon;
+ else
+ file << "data->" << **d->name << ".count";
+
+ file << "; i++) {\n";
+
+ indent.indent_level++;
+ index = "[i]";
+ }
+
+ if (!inl) {
+ file << indent << "if (data->" << **d->name << index << ")\n";
+ indent.indent_level++;
+ }
+
+ file << indent;
+ cpp_output_name(file, sym);
+ file << "_ns::_marshall";