]> git.buserror.net Git - polintos/scott/priv.git/blob - idlcomp/languages/c++/marshall.cc
Add distributors to liability disclaimer. Need to update file headers.
[polintos/scott/priv.git] / idlcomp / languages / c++ / marshall.cc
1 // C++ Marshalling
2 //
3 // This software is copyright (c) 2007 Scott Wood <scott@buserror.net>.
4 // 
5 // This software is provided 'as-is', without any express or implied warranty.
6 // In no event will the authors or contributors be held liable for any damages
7 // arising from the use of this software.
8 // 
9 // Permission is hereby granted to everyone, free of charge, to use, copy,
10 // modify, prepare derivative works of, publish, distribute, perform,
11 // sublicense, and/or sell copies of the Software, provided that the above
12 // copyright notice and disclaimer of warranty be included in all copies or
13 // substantial portions of this software.
14
15 #include "c++.h"
16
17 void CPPFile::output_ifaceinfo(Interface *iface)
18 {
19         extra_newline();
20
21 #if 0
22         file << indent << "void _invoke(::System::RunTime::Array"
23                        << "< ::System::RunTime::ID> objlist,\n"
24              << indent << "             ::System::RunTime::ParamInfoBlock::Segment *segs,\n"
25              << indent << "             int nsegs);\n\n";
26 #endif
27
28         file << indent << "__attribute__((weak)) __attribute__((unused))\n"
29              << indent << "::System::RunTime::IFaceInfo _info = {\n"
30              << indent << "\t&_guid,\n"
31              << indent << "};\n";
32 }
33
34 void CPPFile::output_marshall(CompiledBasicType &cbt, Datum *d)
35 {
36         printf("marshall cbt\n");
37 }
38
39 void CPPFile::align_type(Symbol *sym)
40 {
41         file << indent << "_ctx.buf.align_to(__alignof__(";
42         cpp_output_name(file, sym);
43         file << "));\n";
44 }
45
46 void CPPFile::grow_buf(Symbol *sym)
47 {
48         file << indent << "_ptr = _ctx.buf.grow_by(sizeof(";
49         cpp_output_name(file, sym);
50         file << "));\n";
51 }
52
53 void CPPFile::output_marshall(Struct *sym, Datum *d)
54 {
55         bool is_inline = !d || d->is_inline();
56
57         if (d && !d->is_inline())       {
58                 extra_newline();
59                 file << indent << "if (" << **d->name << ")\n"
60                      << indent << '\t' << **d->name << "->_marshall(_ctx);\n";
61
62                 return;
63         }
64
65         if (!d) {
66                 extra_newline();
67                 align_type(sym);
68                 grow_buf(sym);
69                 
70                 file << indent << "memcpy(_ptr, this, sizeof(*this));\n";
71         }
72         
73         if (sym->is_plain_data()) {
74                 printf("plain data\n");
75                 return;
76         }
77         
78         for (Struct::entries_iterator i = sym->entries_begin();
79              i != sym->entries_end(); ++i)
80         {
81                 extra_newline();
82                 Datum *d = *i;
83                 
84                 if (d->type)
85                         d->type->output_lang(this, trav_marshall, d);
86                 else
87                         output_marshall(d->def.basictype, d);
88         }
89 }
90
91 void CPPFile::output_marshall(Interface *sym, Datum *d)
92 {
93         printf("marshall iface\n");
94 }
95
96 void CPPFile::output_marshall(Enum *sym, Datum *d)
97 {
98         printf("marshall enum\n");
99 }
100
101 void CPPFile::output_marshall(BitField *sym, Datum *d)
102 {
103         printf("marshall bitfield\n");
104 }
105
106 void CPPFile::output_marshall(BasicType *sym, Datum *d)
107 {
108         printf("marshall basictype\n");
109 }
110
111 void CPPFile::output_marshall_pass(Struct *sym, int pass)
112 {
113         switch (pass) {
114                 case trav_nsdecl:
115                         extra_newline();
116                         
117                         file << indent << "int _marshall(::System::RunTime::MarshCtx &_ctx);\n";
118                         file << indent << "void _unmarshall(::System::RunTime::MarshCtx &_ctx);\n";
119                         break;
120
121                 case trav_full:
122                         extra_newline();
123
124                         file << indent << "int _marshall(::System::RunTime::MarshCtx &_ctx)\n"
125                              << indent << "{\n"
126                              << indent << "\tvoid *_ptr;\n";
127
128                         indent.indent_level++;
129                         output_marshall(sym, NULL);
130                         indent.indent_level--;
131
132                         file << indent << "\treturn 0;\n"
133                              << indent << "}\n\n";
134
135                         file << indent << "void _unmarshall(::System::RunTime::Array<uint8_t, ::System::RunTime::ORBMM> buf,\n"
136                              << indent << "                 ::System::RunTime::Array< ::System::_i_Object *, ::System::RunTime::ORBMM> objlist,\n"
137                              << indent << "                 ::System::RunTime::ParamInfoBlock::Segment *segs,\n"
138                              << indent << "                 int nsegs)\n"
139                              << indent << "{\n"
140                              << indent << "}\n";
141
142                         break;
143         }
144 }