X-Git-Url: http://git.buserror.net/cgi-bin/gitweb.cgi?p=polintos%2Fscott%2Fpriv.git;a=blobdiff_plain;f=idlcomp%2Flanguages%2Fc%2B%2B%2Fmarshall.cc;h=ae58040cba55fd19c405063072150d5eca286e6b;hp=bd1f4286f0f6a6ceb84278f60bf45f42449e7e35;hb=b4890229f8a85f10d34090f9ff38a7de5730ce6c;hpb=cc1bee96fd874ff2c85c765f81ec2f4ba4584b9d diff --git a/idlcomp/languages/c++/marshall.cc b/idlcomp/languages/c++/marshall.cc index bd1f428..ae58040 100644 --- a/idlcomp/languages/c++/marshall.cc +++ b/idlcomp/languages/c++/marshall.cc @@ -1,6 +1,6 @@ // C++ Marshalling // -// This software is copyright (c) 2007 Scott Wood . +// This software is copyright (c) 2008 Scott Wood . // // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors or contributors be held liable for any damages @@ -29,28 +29,232 @@ void CPPFile::output_ifaceinfo(Interface *iface) << indent << "::System::RunTime::IFaceInfo _info = {\n" << indent << "\t&_guid,\n" << indent << "};\n"; +} + +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 = ""; - do_extra_newline = true; + 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"; + + if (inl) + file << "_inline(ctx, &"; + else + file << "(ctx, "; + + file << "data->" << **d->name << index + << ", &sptr->" << **d->name << index << ");\n"; + + if (!inl) + indent.indent_level--; + + if (array) { + indent.indent_level--; + file << indent << "}\n"; + } +} + +void CPPFile::output_marshall(Interface *sym, Datum *d) +{ + printf("marshall iface\n"); +} + +void CPPFile::output_marshall(Enum *sym, Datum *d) +{ + if (!d->is_array() || d->is_inline()) + return; + + output_marshall_array(d); } -void CPPFile::output_marshall(Struct *sym, int pass) +void CPPFile::output_marshall(BitField *sym, Datum *d) +{ + if (!d->is_array() || d->is_inline()) + return; + + output_marshall_array(d); +} + +void CPPFile::output_marshall(BasicType *sym, Datum *d) +{ + if (!d->is_array() || d->is_inline()) + return; + + output_marshall_array(d); +} + +void CPPFile::output_marshall(CompiledBasicType &cbt, Datum *d) +{ + if (!d->is_array() || d->is_inline()) + return; + + output_marshall_array(d); +} + +void CPPFile::output_marshall_pass(Struct *sym, int pass) { switch (pass) { case trav_nsdecl: extra_newline(); - file << indent << "int _marshall(::System::RunTime::GrowableArray &buf,\n" - << indent << " ::System::RunTime::GrowableArray< ::System::RunTime::ID, ::System::RunTime::ORBMM> &objlist,\n" - << indent << " ::System::RunTime::GrowableArray< ::System::RunTime::NewObject, ::System::RunTime::ORBMM> &newobjlist,\n" - << indent << " ::System::RunTime::ParamInfoBlock::Segment *segs,\n" - << indent << " int nsegs);\n"; + file << indent << "void *_marshall(::System::RunTime::MarshCtx &ctx,\n" + << indent << " "; + cpp_output_name(file, sym); + file << " *data, "; + cpp_output_name(file, sym); + file << " **link);\n"; - file << indent << "void _unmarshall(::System::RunTime::Array buf,\n" + file << indent << "void *_marshall_inline(::System::RunTime::MarshCtx &ctx,\n" + << indent << " "; + cpp_output_name(file, sym); + file << " *data, "; + cpp_output_name(file, sym); + file << " *sptr);\n"; + + file << indent << "void _unmarshall(::System::RunTime::MarshCtx &ctx,\n" + << indent << " "; + cpp_output_name(file, sym); + file << " *data);\n"; + break; + + case trav_full: + output_marshall_method(sym); + output_marshall_inline_method(sym); + +#if 0 + file << indent << "__attribute__((weak)) __attribute__((unused))\n" + << indent << "void _unmarshall(::System::RunTime::Array buf,\n" << indent << " ::System::RunTime::Array< ::System::_i_Object *, ::System::RunTime::ORBMM> objlist,\n" << indent << " ::System::RunTime::ParamInfoBlock::Segment *segs,\n" - << indent << " int nsegs);\n"; + << indent << " int nsegs)\n" + << indent << "{\n" + << indent << "}\n"; +#endif - do_extra_newline = true; break; } }