added test using own class as argument
[libt2n] / codegen / main.cpp
CommitLineData
e50cc1d6
JT
1#include <libxml++/libxml++.h>
2#include <cassert>
3#include <iostream>
060fbd87
JT
4#include <set>
5#include <fstream>
9d3993e5 6#include <list>
e50cc1d6 7
52b6f93a 8//! convert string to upper case
e035276b
JT
9std::string
10toupper(std::string s) {
11 for (unsigned i=0; i<s.length(); ++i) s[i]=toupper(s[i]);
12 return s;
13}
14
52b6f93a 15//! replace all characters f by r in string s
e035276b
JT
16std::string
17replace(std::string s, char f, char r) {
18 for (unsigned i=0; i<s.length(); ++i) if (s[i]==f) s[i]=r;
19 return s;
20}
21
52b6f93a
JT
22//! strip prefix from string s
23/*!
24 \return string s without prefix or an empty string on error
25 */
e035276b
JT
26std::string
27strip(std::string s, std::string prefix)
28{
29 std::string error;
30 if ( (prefix.length()>s.length() ) || ( std::string(s,0,prefix.length())!=prefix ) ) return error;
31 return std::string(s, prefix.length(), s.length()-prefix.length());
32}
33
52b6f93a 34//! extract group from attributes
25b3f2c1
JT
35std::string
36extract_group(const std::string &attrs)
37{
38 // todo: improve this
39 std::string error;
40 std::string to_match("gccxml(libt2n-");
41 std::string::size_type p(attrs.find(to_match));
42 if (p==std::string::npos) return error;
43 std::string group(attrs, p+to_match.length(), attrs.length());
44 p=group.find_first_of(')');
45 assert(p!=std::string::npos);
46 return std::string(group,0,p);
47}
48
e50cc1d6
JT
49//! get child element by id
50/*!
51 \return pointer to element having id or null on error
52 \todo find libxmlpp pendant
53*/
54const xmlpp::Element* get_element_by_id(const xmlpp::Element* element, const std::string &id)
55{
56 const xmlpp::Attribute* cid = element->get_attribute("id");
57 if ( cid && ( cid->get_value() == id)) return element;
58
59 //Recurse through child nodes:
60 xmlpp::Node::NodeList list = element->get_children();
61 for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
62 {
63 const xmlpp::Element* element = dynamic_cast<const xmlpp::Element*>(*iter);
64 if (element) {
65 const xmlpp::Element* match = get_element_by_id(element, id);
66 if (match) return match;
67 }
68 }
69 return NULL;
70}
71
72//! get namespace by id
73/*!
74 \return namespace name or empty string on error
75*/
76std::string get_namespace(const xmlpp::Element* root, const std::string &id)
77{
78 std::string error;
79 const xmlpp::Element* element(get_element_by_id(root, id));
80 if ((!element)||(!element->get_attribute("name"))) return error;
81 return element->get_attribute("name")->get_value();
82}
83
52b6f93a
JT
84//! get default group
85std::string get_default_group(const xmlpp::Element* root) {
86 std::string error;
87
88 if ( (root->get_attribute("name"))
89 && (root->get_attribute("attributes"))
90 && (root->get_name() == "Typedef")
91 && (root->get_attribute("name")->get_value()=="libt2n_default_group"))
92 return extract_group(root->get_attribute("attributes")->get_value());
93
94 //Recurse through child nodes:
95 xmlpp::Node::NodeList list = root->get_children();
96 for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
97 {
98 if (const xmlpp::Element* elem=dynamic_cast<const xmlpp::Element*>(*iter)) {
99 std::string ret(get_default_group(elem));
100 if (!ret.empty()) return ret;
101 }
102 }
103 return error;
104}
e035276b
JT
105
106struct type_info
107{
108 std::string name;
109 std::string noref_name;
110 bool operator==(const type_info& o) {return (name==o.name) && (noref_name == o.noref_name);}
9d3993e5 111 std::string noref() const {return noref_name.empty() ? name : noref_name;}
e035276b
JT
112};
113
114std::ostream &operator<<(std::ostream &o, const type_info &t) {
115 o << t.name;
116 return o;
117}
118
e50cc1d6
JT
119//! get type by id
120/*!
121 \return type name or empty string on error
122*/
e035276b 123type_info get_type(const xmlpp::Element* root, const std::string &id)
e50cc1d6 124{
e035276b 125 type_info error;
e50cc1d6
JT
126 const xmlpp::Element* element(get_element_by_id(root, id));
127 if (!element) return error;
128
129 // TODO: not yet complete
130 // if we recurse - when do we stop?
131 // if it is a typedef? yes? (hmm if the typedef is in the file parsed this will not work)
060fbd87 132
9d3993e5 133 // TODO: const and reference types handling is a ugly hack
060fbd87 134
e50cc1d6
JT
135 std::string tag(element->get_name());
136 if (tag=="ReferenceType") {
137 assert(element->get_attribute("type"));
e035276b 138 type_info ret(get_type(root, element->get_attribute("type")->get_value()));
e50cc1d6 139 if (ret==error) return error;
e035276b
JT
140 // at the moment we only support const &
141 // todo: nice error message!
142 if ((ret.noref_name=strip(ret.name,"const ")).empty()) return error;
143 ret.name=ret.name+"&";
144 return ret;
e50cc1d6
JT
145 }else if (tag=="CvQualifiedType") {
146 assert(element->get_attribute("type"));
e035276b 147 type_info ret(get_type(root, element->get_attribute("type")->get_value()));
e50cc1d6 148 if (ret==error) return error;
e035276b
JT
149 ret.name=std::string("const ")+ret.name;
150 return ret;
e50cc1d6
JT
151 }
152
153 assert(element->get_attribute("name"));
e035276b 154 type_info ret;
fb5c13c6
JT
155 if (element->get_attribute("context")) {
156 ret.name=get_namespace(root, element->get_attribute("context")->get_value());
157 if (ret.name!="::")
158 ret.name+="::";
159 else
160 // do not explicitely add ::
161 ret.name="";
162 }
9d3993e5 163 ret.name+=element->get_attribute("name")->get_value();
e035276b 164 return ret;
e50cc1d6
JT
165}
166
060fbd87
JT
167struct t2n_procedure
168{
9d3993e5 169 typedef std::list<std::pair<std::string, type_info> > Args;
e50cc1d6 170
060fbd87 171 std::string group;
e035276b 172 type_info ret_type;
060fbd87 173 std::string name;
52b6f93a 174 std::string mangled;
060fbd87 175 Args args;
e50cc1d6 176
060fbd87 177 std::string ret_classname() const {
52b6f93a 178 return name+mangled+"_res";
060fbd87
JT
179 }
180 std::string cmd_classname() const {
52b6f93a 181 return name+mangled+"_cmd";
060fbd87
JT
182 }
183};
e50cc1d6 184
060fbd87
JT
185std::ostream &operator<<(std::ostream &o, const t2n_procedure::Args &args) {
186 for (t2n_procedure::Args::const_iterator it=args.begin();it!=args.end();++it) {
187 if (it!=args.begin()) o << ", ";
188 o << it->second << " " << it->first;
189 }
190 return o;
191}
e50cc1d6 192
060fbd87
JT
193std::ostream &operator<<(std::ostream &o, const t2n_procedure &f) {
194 o << f.ret_type << " " << f.name << "(" << f.args << ")";
195 return o;
196}
e50cc1d6 197
060fbd87
JT
198class Parser
199{
200public:
201 Parser(const std::string &fname) : m_fname(fname) {}
e50cc1d6 202
060fbd87
JT
203 std::list<t2n_procedure> get_procedures() {
204 xmlpp::DomParser parser;
205 // parser.set_validate();
206 parser.set_substitute_entities(); //We just want the text to be resolved/unescaped automatically.
207 parser.parse_file(m_fname);
208 if(parser)
209 {
210 //Walk the tree:
211 const xmlpp::Node* pNode = parser.get_document()->get_root_node(); //deleted by DomParser.
212 const xmlpp::Element* root = dynamic_cast<const xmlpp::Element*>(pNode);
213 assert(root);
214 visit_node(root);
e50cc1d6 215 }
060fbd87 216 return m_procedures;
e50cc1d6 217 }
060fbd87
JT
218protected:
219 std::string m_fname;
220 std::list<t2n_procedure> m_procedures;
221
222 void parse_function(const xmlpp::Element* root, const xmlpp::Node* node) {
223 const xmlpp::Element* element = dynamic_cast<const xmlpp::Element*>(node);
224 if (!element) return;
225
226 const xmlpp::Attribute* attributes = element->get_attribute("attributes");
227 const xmlpp::Attribute* name = element->get_attribute("name");
52b6f93a 228 const xmlpp::Attribute* mangled = element->get_attribute("mangled");
060fbd87 229 const xmlpp::Attribute* returns = element->get_attribute("returns");
52b6f93a 230 if ((!attributes)||(!name)||(!mangled)||(!returns)) return;
060fbd87
JT
231
232 // check wether the procedure is marked (TODO: improve)
233 // attributes are speparated by spaces?
060fbd87 234
060fbd87 235 t2n_procedure f;
25b3f2c1
JT
236 f.group=extract_group(attributes->get_value());
237 if (f.group.empty()) return;
238 // todo: handle default group
52b6f93a 239 if (f.group=="default") f.group=get_default_group(root);
e50cc1d6 240
060fbd87
JT
241 // we need the return type
242 f.ret_type=get_type(root, returns->get_value());
243 f.name=name->get_value();
52b6f93a 244 f.mangled=mangled->get_value();
060fbd87
JT
245
246 xmlpp::Node::NodeList list = node->get_children("Argument");
247 for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
248 {
249 const xmlpp::Element* arg = dynamic_cast<const xmlpp::Element*>(*iter);
250 if ( arg ) {
251 assert(arg->get_name() == "Argument");
252 assert(arg->get_attribute("name"));
253 assert(arg->get_attribute("type"));
9d3993e5 254 f.args.push_back(std::pair<std::string, type_info>(arg->get_attribute("name")->get_value(), get_type(root, arg->get_attribute("type")->get_value())));
060fbd87
JT
255 }
256 }
9d3993e5 257 std::cerr << "Found function: " << f << std::endl;
060fbd87 258 m_procedures.push_back(f);
e50cc1d6 259 }
e50cc1d6 260
060fbd87
JT
261 void visit_node(const xmlpp::Element* root, const xmlpp::Node* node = NULL, unsigned int indentation = 0)
262 {
263 if (!node) node=root;
060fbd87
JT
264
265 const xmlpp::ContentNode* nodeContent = dynamic_cast<const xmlpp::ContentNode*>(node);
266 const xmlpp::TextNode* nodeText = dynamic_cast<const xmlpp::TextNode*>(node);
267 const xmlpp::CommentNode* nodeComment = dynamic_cast<const xmlpp::CommentNode*>(node);
e50cc1d6 268
060fbd87
JT
269 if(nodeText && nodeText->is_white_space()) //Let's ignore the indenting - you don't always want to do this.
270 return;
e50cc1d6 271
060fbd87 272 std::string nodename = node->get_name();
e50cc1d6 273
060fbd87
JT
274 if(!nodeText && !nodeComment && !nodename.empty()) //Let's not say "name: text".
275 {
52b6f93a 276 if (node->get_name() == "Function") parse_function(root, node);
060fbd87 277 }
060fbd87
JT
278 if(!nodeContent)
279 {
280 //Recurse through child nodes:
281 xmlpp::Node::NodeList list = node->get_children();
282 for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
283 {
284 visit_node(root, *iter, indentation + 2); //recursive
285 }
286 }
e50cc1d6 287 }
060fbd87
JT
288};
289
290//! find used groups
291std::set<std::string>
292used_groups(const std::list<t2n_procedure> &funcs) {
293 typedef std::set<std::string> Groups;
294 Groups groups;
295 for (std::list<t2n_procedure>::const_iterator it=funcs.begin();it!=funcs.end();++it)
296 // since we use std::set each group is inserted only once
297 groups.insert(it->group);
298 return groups;
299}
300
301void output_common_hpp(std::ostream &o, const std::list<t2n_procedure> &procs) {
302 std::set<std::string> groups(used_groups(procs));
303
060fbd87
JT
304 for (std::set<std::string>::iterator it=groups.begin();it!=groups.end();++it) {
305 o << "class cmd_group_" << *it << " : public libt2n::command\n"
306 << "{\n"
307 << "private:\n"
308 << " friend class boost::serialization::access;\n"
309 << " template<class Archive>\n"
fb5c13c6 310 << " void serialize(Archive & ar, const unsigned int /* version */)\n"
060fbd87
JT
311 << " {ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::command);}\n"
312 << "};\n";
e50cc1d6 313 }
060fbd87
JT
314
315 for (std::list<t2n_procedure>::const_iterator it=procs.begin();it!=procs.end();++it) {
316 o << "class " << it->ret_classname() << " : public libt2n::result\n"
317 << "{\n"
318 << "private:\n"
319 << " " << it->ret_type << " res;\n"
320 << " friend class boost::serialization::access;\n"
321 << " template<class Archive>\n"
fb5c13c6 322 << " void serialize(Archive & ar, const unsigned int /* version */)\n"
060fbd87
JT
323 << " {\n"
324 << " ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::result);\n"
325 << " ar & BOOST_SERIALIZATION_NVP(res);\n"
326 << " }\n"
327 << "public:\n"
e035276b 328 << " " << it->ret_classname() << "() {}\n"
060fbd87
JT
329 << " " << it->ret_classname() << "(const " << it->ret_type << " &_res) : res(_res) {}\n"
330 << " " << it->ret_type << " get_data() { return res; }\n"
331 << "};\n";
e50cc1d6 332 }
060fbd87
JT
333 for (std::list<t2n_procedure>::const_iterator it=procs.begin();it!=procs.end();++it) {
334 o << "class " << it->cmd_classname() << " : public " << "cmd_group_" << it->group << "\n"
335 << "{\n"
336 << "private:\n";
337 for (t2n_procedure::Args::const_iterator ait=it->args.begin();ait!=it->args.end();++ait) {
e035276b 338 o << " " << ait->second.noref() << " " << ait->first << ";\n";
060fbd87
JT
339 }
340 o << " friend class boost::serialization::access;\n"
341 << " template<class Archive>\n"
fb5c13c6 342 << " void serialize(Archive & ar, const unsigned int /* version */)\n"
060fbd87
JT
343 << " {\n"
344 << " ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(cmd_group_" << it->group << ");\n";
345 for (t2n_procedure::Args::const_iterator ait=it->args.begin();ait!=it->args.end();++ait) {
346 o << " ar & BOOST_SERIALIZATION_NVP(" << ait->first << ");\n";
347 }
e50cc1d6 348
060fbd87
JT
349 // default constructor
350 o << " }\n"
351 << "\n"
352 << "public:\n"
353 << " " << it->cmd_classname() << "() {}\n";
354
355 // constructor taking all arguments
356 o << " " << it->cmd_classname() << "(";
357 for (t2n_procedure::Args::const_iterator ait=it->args.begin();ait!=it->args.end();++ait) {
358 if (ait!=it->args.begin()) o << ", ";
359 o << ait->second << " _" << ait->first;
360 }
361 o << ") : ";
362 for (t2n_procedure::Args::const_iterator ait=it->args.begin();ait!=it->args.end();++ait) {
363 if (ait!=it->args.begin()) o << ", ";
364 o << ait->first << "(_" << ait->first << ")";
365 }
366 o << " {}\n"
367 << " libt2n::result* operator()();\n"
368 << "};\n";
e50cc1d6 369 }
060fbd87
JT
370}
371
372void output_common_cpp(std::ostream &o, const std::list<t2n_procedure> &procs, const std::string &common_hpp) {
373 std::set<std::string> groups(used_groups(procs));
374
375 o << "#include \"" << common_hpp << "\"\n"
e035276b 376 << "#include <boost/serialization/export.hpp>\n"
060fbd87
JT
377 << "\n"
378 << "/* register types with boost serialization */\n";
379 for (std::set<std::string>::iterator it=groups.begin();it!=groups.end();++it) {
380 o << "BOOST_CLASS_EXPORT(cmd_group_" << *it << ")\n";
e50cc1d6 381 }
060fbd87
JT
382 for (std::list<t2n_procedure>::const_iterator it=procs.begin();it!=procs.end();++it) {
383 o << "BOOST_CLASS_EXPORT("<<it->ret_classname()<<")\n"
384 << "BOOST_CLASS_EXPORT("<<it->cmd_classname()<<")\n";
e50cc1d6 385 }
060fbd87 386}
e50cc1d6 387
060fbd87
JT
388void output_client_hpp(std::ostream &o, const std::list<t2n_procedure> &procs) {
389 std::set<std::string> groups(used_groups(procs));
e50cc1d6 390
060fbd87
JT
391 o << "#include <command_client.hxx>\n";
392
393 for (std::set<std::string>::iterator it=groups.begin();it!=groups.end();++it) {
394 o << "class cmd_group_" << *it << "_client : public libt2n::command_client\n"
395 << "{\n"
396 << "public:\n"
397 << "cmd_group_" << *it << "_client(libt2n::client_connection &_c,\n"
398 << " long long _command_timeout_usec=command_timeout_usec_default,\n"
399 << " long long _hello_timeout_usec=hello_timeout_usec_default)\n"
400 << " : libt2n::command_client(_c,_command_timeout_usec,_hello_timeout_usec)\n"
401 << " {}\n";
402 for (std::list<t2n_procedure>::const_iterator pit=procs.begin();pit!=procs.end();++pit) {
403 if (pit->group==*it) {
404 o << " " << *pit << ";\n";
405 }
e50cc1d6 406 }
060fbd87
JT
407 o << "};\n";
408 }
409}
e50cc1d6 410
060fbd87
JT
411void output_client_cpp(std::ostream &o, const std::list<t2n_procedure> &procs, const std::string &common_hpp, const std::string &common_cpp, const std::string &client_hpp) {
412 std::set<std::string> groups(used_groups(procs));
413
414 o << "#include \"" << client_hpp << "\"\n"
415 << "#include \"" << common_hpp << "\"\n"
416 << "// fake\n";
417 for (std::list<t2n_procedure>::const_iterator it=procs.begin();it!=procs.end();++it) {
418 o << "libt2n::result* " << it->cmd_classname() << "::operator()() { return NULL; }\n";
419 }
420
421 for (std::set<std::string>::iterator it=groups.begin();it!=groups.end();++it) {
422 for (std::list<t2n_procedure>::const_iterator pit=procs.begin();pit!=procs.end();++pit) {
423 if (pit->group==*it) {
424 o << pit->ret_type << " cmd_group_" << *it << "_client::" << pit->name << "(" << pit->args << ")\n"
425 << "{\n"
426 << " libt2n::result_container rc;\n"
427 << " send_command(new " << pit->cmd_classname() << "(";
428 for (t2n_procedure::Args::const_iterator ait=pit->args.begin();ait!=pit->args.end();++ait) {
429 if (ait!=pit->args.begin()) o << ", ";
430 o << ait->first;
431 }
432 o << "), rc);\n"
433 << " " << pit->ret_classname() << "* res=dynamic_cast<" << pit->ret_classname() << "*>(rc.get_result());\n"
434 << " if (!res) throw libt2n::t2n_communication_error(\"result object of wrong type\");\n"
435 << " return res->get_data();\n"
436 << "}\n";
437 }
e50cc1d6
JT
438 }
439 }
060fbd87
JT
440
441 // include in this compilation unit to ensure the compilation unit is used
442 // see also:
443 // http://www.google.de/search?q=g%2B%2B+static+initializer+in+static+library
444 o << "#include \"" << common_cpp << "\"\n";
445}
446
447void output_server_cpp(std::ostream &o, const std::list<t2n_procedure> &procs, const std::string &common_hpp, const std::string &common_cpp) {
448 o << "#include \"" << common_hpp << "\"\n";
449
450 for (std::list<t2n_procedure>::const_iterator it=procs.begin();it!=procs.end();++it) {
451 o << *it << ";\n";
452 o << "libt2n::result* " << it->cmd_classname() << "::operator()() { return new " << it->ret_classname() << "(" << it->name << "(";
453 for (t2n_procedure::Args::const_iterator ait=it->args.begin();ait!=it->args.end();++ait) {
454 if (ait!=it->args.begin()) o << ", ";
455 o << ait->first;
e50cc1d6 456 }
060fbd87 457 o << ")); }\n";
e50cc1d6 458 }
060fbd87
JT
459 o << "#include \"" << common_cpp << "\"\n";
460}
461
060fbd87
JT
462struct header_file : public std::ofstream
463{
464 header_file(const char* fname) : std::ofstream(fname) {
465 std::cerr << "create header: '" << fname << "'" << std::endl;
466 std::string macro(replace(toupper(fname),'.','_'));
467 *this << "// automatically generated code - do not edit\n" << std::endl;
468 *this << "#ifndef " << macro << "\n"
469 << "#define " << macro << "\n";
470 }
471 ~header_file() {
472 *this << "#endif" << std::endl;
473 }
474};
475
476struct cpp_file : public std::ofstream
477{
478 cpp_file(const char* fname) : std::ofstream(fname) {
479 std::cerr << "create cpp: '" << fname << "'" << std::endl;
480 *this << "// automatically generated code - do not edit\n" << std::endl;
481 }
482};
483
d5b431f8
JT
484std::list<std::string>
485get_includes(const std::string &fname)
486{
487 // grep "#include" fname
488 std::ifstream in(fname.c_str());
489 std::string line;
490 std::list<std::string> ret;
491 while (std::getline(in,line)) {
492 if (line.find("#include")!=std::string::npos)
493 ret.push_back(line);
494 }
495 return ret;
496}
497
498void
499paste_includes(std::ostream &o, std::list<std::string> &i)
500{
501 o << std::endl
502 << "// copied includes begin" << std::endl;
503 for (std::list<std::string>::const_iterator it=i.begin(); it!=i.end(); ++it)
504 o << *it << std::endl;
505 o << "// copied includes end" << std::endl
506 << std::endl;
507}
508
509struct RemoveGenerated
510{
511 RemoveGenerated(const std::string &_prefix) : prefix(_prefix) {}
512 bool operator()(const std::string &s) const {
513 return (s.find(prefix+"common.hxx")!=std::string::npos);
514 }
515 const std::string &prefix;
516};
517
060fbd87
JT
518int
519main(int argc, char* argv[])
e50cc1d6 520{
d5b431f8
JT
521 if (argc != 4) {
522 std::cerr << "Usage: " << argv[0] << " header-file gccxml-file outputprefix" << std::endl;
f8b78aa8
JT
523 return 1;
524 }
d5b431f8
JT
525 std::string headerfile(argv[1]);
526 std::string xmlfile(argv[2]);
527 std::string prefix(argv[3]);
528 std::list<std::string> includes(get_includes(headerfile));
529 remove_if(includes.begin(), includes.end(), RemoveGenerated(prefix));
530 includes.erase(remove_if(includes.begin(), includes.end(), RemoveGenerated(prefix)), includes.end());
531
532 paste_includes(std::cerr, includes);
e50cc1d6 533
d5b431f8 534 Parser parser(xmlfile);
060fbd87
JT
535 std::list<t2n_procedure> procedures(parser.get_procedures());
536
537 std::cerr << "Procedures:" << std::endl;
538 for (std::list<t2n_procedure>::const_iterator it=procedures.begin();it!=procedures.end();++it)
539 std::cerr << *it << ";" << std::endl;
540
541 std::set<std::string> groups(used_groups(procedures));
542 std::cerr << "Used groups:" << std::endl;
543 for (std::set<std::string>::const_iterator it=groups.begin();it!=groups.end();++it)
544 std::cerr << *it << std::endl;
545
060fbd87
JT
546 std::string common_hpp_fname(prefix+"common.hxx");
547 std::string common_cpp_fname(prefix+"common.cpp");
548 std::string client_hpp_fname(prefix+"client.hxx");
549 std::string client_cpp_fname(prefix+"client.cpp");
e035276b 550 std::string server_cpp_fname(prefix+"server.cpp");
060fbd87
JT
551
552 header_file common_hpp(common_hpp_fname.c_str());
d5b431f8
JT
553 common_hpp << "#include \"codegen-stubhead.hxx\"\n";
554 paste_includes(common_hpp, includes);
555
060fbd87
JT
556 output_common_hpp(common_hpp, procedures);
557
558 cpp_file common_cpp(common_cpp_fname.c_str());
e035276b 559 output_common_cpp(common_cpp, procedures, common_hpp_fname);
060fbd87
JT
560
561 header_file client_hpp(client_hpp_fname.c_str());
fb5c13c6 562 client_hpp << "#include \"codegen-stubhead.hxx\"\n";
d5b431f8 563 // we can't paste the includes before codegen-stubhead.hxx was included
fb5c13c6 564 paste_includes(client_hpp, includes);
060fbd87
JT
565 output_client_hpp(client_hpp, procedures);
566
567 cpp_file client_cpp(client_cpp_fname.c_str());
568 output_client_cpp(client_cpp, procedures, common_hpp_fname, common_cpp_fname, client_hpp_fname);
e50cc1d6 569
060fbd87
JT
570 cpp_file server_cpp(server_cpp_fname.c_str());
571 output_server_cpp(server_cpp, procedures, common_hpp_fname, common_cpp_fname);
e50cc1d6
JT
572 return 0;
573}