ca912219cb6b2c9d88c882798e378d9b4d176fde
[libt2n] / codegen / main.cpp
1 /*
2     Copyright (C) 2006-2008
3     intra2net.com
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19
20 #include <libxml++/libxml++.h>
21 #include <cassert>
22 #include <iostream>
23 #include <set>
24 #include <fstream>
25 #include <list>
26 #include <stdexcept>
27 #include <boost/lexical_cast.hpp>
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32
33 //! map group to class name
34 std::string groupClass(const std::string &group)
35 {
36     return std::string("cmd_group_")+group;
37 }
38
39 //! convert string to upper case
40 std::string toupper(std::string s)
41 {
42     for (unsigned i=0; i<s.length(); ++i) s[i]=toupper(s[i]);
43     return s;
44 }
45
46 //! replace all characters f by r in string s
47 std::string replace(std::string s, char f, char r)
48 {
49     for (unsigned i=0; i<s.length(); ++i) if (s[i]==f) s[i]=r;
50     return s;
51 }
52
53 //! strip prefix from string s
54 /*!
55   \return string s without prefix or an empty string on error
56  */
57 std::string strip(std::string s, std::string prefix)
58 {
59     std::string error;
60     if ( (prefix.length()>s.length() ) || ( std::string(s,0,prefix.length())!=prefix ) ) return error;
61     return std::string(s, prefix.length(), s.length()-prefix.length());
62 }
63
64 //! get child element by id
65 /*!
66   \return pointer to element having id or null on error
67   \todo find libxmlpp pendant
68 */
69 const xmlpp::Element* get_element_by_id(const xmlpp::Element* element, const std::string &id)
70 {
71     const xmlpp::Attribute* cid = element->get_attribute("id");
72     if ( cid && ( cid->get_value() == id)) return element;
73
74     //Recurse through child nodes:
75     xmlpp::Node::NodeList list = element->get_children();
76     for (xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
77     {
78         const xmlpp::Element* element = dynamic_cast<const xmlpp::Element*>(*iter);
79         if (element)
80         {
81             const xmlpp::Element* match = get_element_by_id(element, id);
82             if (match) return match;
83         }
84     }
85     return NULL;
86 }
87
88 std::string get_file(const xmlpp::Element* root, const std::string &file_id)
89 {
90     std::string error;
91     const xmlpp::Element* e=get_element_by_id(root, file_id);
92     if ((!e)||(!e->get_attribute("name"))) return error;
93     return e->get_attribute("name")->get_value();
94 }
95
96 //! get namespace by id
97 /*!
98   \return namespace name or empty string on error
99 */
100 std::string get_namespace(const xmlpp::Element* root, const std::string &id)
101 {
102     std::string error;
103     const xmlpp::Element* element(get_element_by_id(root, id));
104     // [RP:20071024]: use "demangled" attribute instead of "name" to cover nested namespaces:
105     if ((!element)||(!element->get_attribute("demangled"))) return error;
106     return element->get_attribute("demangled")->get_value();
107 }
108
109 //! procedure marked for export?
110 bool is_marked(const std::string &attrs)
111 {
112     // todo: improve this
113     std::string to_match("gccxml(libt2n-");
114     std::string::size_type p(attrs.find(to_match));
115     return (p!=std::string::npos);
116 }
117
118 struct type_info
119 {
120     std::string name;
121     std::string noref_name;
122     bool operator==(const type_info& o) {return (name==o.name) && (noref_name == o.noref_name);}
123     std::string noref() const {return noref_name.empty() ? name : noref_name;}
124     bool isVoid() const {return name=="void";}
125 };
126
127 std::ostream &operator<<(std::ostream &o, const type_info &t)
128 {
129     o << t.name;
130     return o;
131 }
132
133 struct parse_error : public std::runtime_error
134 {
135     parse_error(const std::string &file, unsigned line, const std::string &msg)
136             : std::runtime_error(file+":"+boost::lexical_cast<std::string>(line)+": error: "+msg)
137     {}
138 };
139
140 //! get type by id
141 /*!
142   \return type name or empty string on error
143 */
144 type_info get_type(const xmlpp::Element* root, const std::string &id)
145 {
146     type_info error;
147     const xmlpp::Element* element(get_element_by_id(root, id));
148     if (!element) return error;
149
150     // TODO: not yet complete
151     // if we recurse - when do we stop?
152     // if it is a typedef? yes? (hmm if the typedef is in the file parsed this will not work)
153
154     // TODO: const and reference types handling is a ugly hack
155
156     std::string tag(element->get_name());
157     if (tag=="ReferenceType")
158     {
159         assert(element->get_attribute("type"));
160         type_info ret(get_type(root, element->get_attribute("type")->get_value()));
161         if (ret==error) return error;
162         // at the moment we only support const &
163         // todo: nice error message!
164         if ((ret.noref_name=strip(ret.name,"const ")).empty()) return error;
165         ret.name=ret.name+"&";
166         return ret;
167     }
168     else if (tag=="CvQualifiedType")
169     {
170         assert(element->get_attribute("type"));
171         type_info ret(get_type(root, element->get_attribute("type")->get_value()));
172         if (ret==error) return error;
173         ret.name=std::string("const ")+ret.name;
174         return ret;
175     }
176     else if (tag=="PointerType")
177     {
178         // todo: nearly the same as reference type handling
179         assert(element->get_attribute("type"));
180         type_info ret(get_type(root, element->get_attribute("type")->get_value()));
181         if (ret==error) return error;
182         // at the moment we only support const &
183         // todo: nice error message!
184         if ((ret.noref_name=strip(ret.name,"const ")).empty()) return error;
185         ret.name=ret.name+"*";
186         return ret;
187     }
188
189     assert(element->get_attribute("name"));
190     type_info ret;
191     if (element->get_attribute("context"))
192     {
193         ret.name=get_namespace(root, element->get_attribute("context")->get_value());
194         if (ret.name!="::")
195             ret.name+="::";
196         else
197             // do not explicitely add ::
198             ret.name="";
199     }
200     ret.name+=element->get_attribute("name")->get_value();
201     return ret;
202 }
203
204 struct Arg
205 {
206     std::string name;
207     type_info type;
208     std::string defaultArg;
209 };
210
211 struct t2n_procedure
212 {
213     typedef std::list<Arg> Args;
214
215     type_info ret_type;
216     std::string name;
217     std::string mangled;
218     Args  args;
219
220     std::string ret_classname() const
221     {
222         return name+mangled+"_res";
223     }
224     std::string cmd_classname() const
225     {
226         return name+mangled+"_cmd";
227     }
228     bool hasReturn() const {return !ret_type.isVoid();}
229 };
230
231 std::ostream &operator<<(std::ostream &o, const t2n_procedure::Args &args)
232 {
233     for (t2n_procedure::Args::const_iterator it=args.begin();it!=args.end();++it)
234     {
235         if (it!=args.begin()) o << ", ";
236         o << it->type << " " << it->name;
237
238         if (!it->defaultArg.empty())
239             o << "=" << it->defaultArg;
240     }
241     return o;
242 }
243
244 std::ostream &operator<<(std::ostream &o, const t2n_procedure &f)
245 {
246     o << f.ret_type << " " << f.name << "(" << f.args << ")";
247     return o;
248 }
249
250 std::pair<std::string, unsigned>
251 get_file_and_line(const xmlpp::Element* root, const xmlpp::Element* element)
252 {
253     return std::pair<std::string, unsigned>(get_file(root, element->get_attribute("file")->get_value()),
254                                             boost::lexical_cast<unsigned>(element->get_attribute("line")->get_value())-1);
255 }
256
257 std::string get_file_and_line_as_string(const xmlpp::Element* root, const xmlpp::Element* element)
258 {
259     std::pair<std::string, unsigned> fl(get_file_and_line(root,element));
260     return std::string(fl.first)+":"+boost::lexical_cast<std::string>(fl.second);
261 }
262
263 class Parser
264 {
265 public:
266     Parser(const std::string &fname) : m_fname(fname) {}
267
268     std::list<t2n_procedure> get_procedures()
269     {
270         xmlpp::DomParser parser;
271         //    parser.set_validate();
272         parser.set_substitute_entities(); //We just want the text to be resolved/unescaped automatically.
273         parser.parse_file(m_fname);
274         if (parser)
275         {
276             //Walk the tree:
277             const xmlpp::Node* pNode = parser.get_document()->get_root_node(); //deleted by DomParser.
278             const xmlpp::Element* root = dynamic_cast<const xmlpp::Element*>(pNode);
279             assert(root);
280             visit_node(root);
281         }
282         return m_procedures;
283     }
284 protected:
285     std::string m_fname;
286     std::list<t2n_procedure> m_procedures;
287
288     void parse_function(const xmlpp::Element* root, const xmlpp::Node* node)
289     {
290         const xmlpp::Element* element = dynamic_cast<const xmlpp::Element*>(node);
291         if (!element) return;
292
293         const xmlpp::Attribute* attributes = element->get_attribute("attributes");
294         const xmlpp::Attribute* name = element->get_attribute("name");
295         const xmlpp::Attribute* mangled = element->get_attribute("mangled");
296         const xmlpp::Attribute* returns = element->get_attribute("returns");
297         if ((!attributes)||(!name)||(!mangled)||(!returns)) return;
298
299         // check wether the procedure is marked (TODO: improve)
300         // attributes are speparated by spaces?
301
302         t2n_procedure f;
303         if (!is_marked(attributes->get_value())) return;
304
305         // we need the return type
306         f.ret_type=get_type(root, returns->get_value());
307         f.name=name->get_value();
308         f.mangled=mangled->get_value();
309
310         xmlpp::Node::NodeList list = node->get_children("Argument");
311         for (xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
312         {
313             const xmlpp::Element* arg = dynamic_cast<const xmlpp::Element*>(*iter);
314             if ( arg )
315             {
316                 struct Arg a;
317
318                 assert(arg->get_name() == "Argument");
319
320                 assert(arg->get_attribute("name"));
321                 a.name=arg->get_attribute("name")->get_value();
322
323                 assert(arg->get_attribute("type"));
324                 a.type=get_type(root, arg->get_attribute("type")->get_value());
325
326                 if(arg->get_attribute("default"))
327                     a.defaultArg=arg->get_attribute("default")->get_value();
328
329                 // todo: ugly - could be any other error
330                 if (a.type.name.empty())
331                 {
332                     assert(element->get_attribute("file"));
333                     assert(element->get_attribute("line"));
334                     std::pair<std::string, unsigned> file_and_line(get_file_and_line(root, element));
335                     throw parse_error(file_and_line.first,
336                                       file_and_line.second,
337                                       std::string("type of parameter '")+a.name+"' not (yet?) supported");
338                 }
339
340                 f.args.push_back(a);
341             }
342         }
343         std::cerr << get_file_and_line_as_string(root, element) << ":\texport procedure: " << f << std::endl;
344         m_procedures.push_back(f);
345     }
346
347     void visit_node(const xmlpp::Element* root, const xmlpp::Node* node = NULL, unsigned int indentation = 0)
348     {
349         if (!node) node=root;
350
351         const xmlpp::ContentNode* nodeContent = dynamic_cast<const xmlpp::ContentNode*>(node);
352         const xmlpp::TextNode* nodeText = dynamic_cast<const xmlpp::TextNode*>(node);
353         const xmlpp::CommentNode* nodeComment = dynamic_cast<const xmlpp::CommentNode*>(node);
354
355         if (nodeText && nodeText->is_white_space()) //Let's ignore the indenting - you don't always want to do this.
356             return;
357
358         std::string nodename = node->get_name();
359
360         if (!nodeText && !nodeComment && !nodename.empty()) //Let's not say "name: text".
361         {
362             if (node->get_name() == "Function") parse_function(root, node);
363         }
364         if (!nodeContent)
365         {
366             //Recurse through child nodes:
367             xmlpp::Node::NodeList list = node->get_children();
368             for (xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter)
369             {
370                 visit_node(root, *iter, indentation + 2); //recursive
371             }
372         }
373     }
374 };
375
376 void output_common_hpp(std::ostream &o, const std::string &group, const std::list<t2n_procedure> &procs)
377 {
378     o << "class " << groupClass(group) << " : public libt2n::command\n"
379     << "{\n"
380     << "private:\n"
381     << " friend class boost::serialization::access;\n"
382     << " template<class Archive>\n"
383     << " void serialize(Archive & ar, const unsigned int /* version */)\n"
384     << " {ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::command);}\n"
385     << "};\n";
386
387     for (std::list<t2n_procedure>::const_iterator it=procs.begin();it!=procs.end();++it)
388     {
389         o << "class " << it->ret_classname() << " : public libt2n::result\n"
390         << "{\n"
391         << "private:\n";
392         if (it->hasReturn())
393             o << " " << it->ret_type << " res;\n";
394         o << " friend class boost::serialization::access;\n"
395         << " template<class Archive>\n"
396         << " void serialize(Archive & ar, const unsigned int /* version */)\n"
397         << " {\n"
398         << "  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(libt2n::result);\n";
399         if (it->hasReturn())
400             o << "  ar & BOOST_SERIALIZATION_NVP(res);\n";
401         o << " }\n"
402         << "public:\n"
403         << " " << it->ret_classname() << "() {}\n";
404         if (it->hasReturn())
405         {
406             o << " " << it->ret_classname() << "(const " << it->ret_type << " &_res) : res(_res) {}\n"
407             << " " << it->ret_type << " get_data() { return res; }\n";
408         }
409         o << "};\n";
410     }
411     for (std::list<t2n_procedure>::const_iterator it=procs.begin();it!=procs.end();++it)
412     {
413         o << "class " << it->cmd_classname() << " : public " << groupClass(group) << "\n"
414         << "{\n"
415         << "private:\n";
416         for (t2n_procedure::Args::const_iterator ait=it->args.begin();ait!=it->args.end();++ait)
417         {
418             o << " " << ait->type.noref() << " " << ait->name << ";\n";
419         }
420         o << " friend class boost::serialization::access;\n"
421         << " template<class Archive>\n"
422         << " void serialize(Archive & ar, const unsigned int /* version */)\n"
423         << " {\n"
424         << "  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(" << groupClass(group) << ");\n";
425         for (t2n_procedure::Args::const_iterator ait=it->args.begin();ait!=it->args.end();++ait)
426         {
427             o << "  ar & BOOST_SERIALIZATION_NVP(" << ait->name << ");\n";
428         }
429
430         // default constructor
431         o << " }\n"
432         << "\n"
433         << "public:\n"
434         << " " << it->cmd_classname() << "() {}\n";
435
436         // constructor taking all arguments
437         if (!it->args.empty())
438         {
439             o << " " << it->cmd_classname() << "(";
440             for (t2n_procedure::Args::const_iterator ait=it->args.begin();ait!=it->args.end();++ait)
441             {
442                 if (ait!=it->args.begin()) o << ", ";
443                 o << ait->type << " _" << ait->name;
444             }
445             o << ") : ";
446             for (t2n_procedure::Args::const_iterator ait=it->args.begin();ait!=it->args.end();++ait)
447             {
448                 if (ait!=it->args.begin()) o << ", ";
449                 // pointers are const pointers and must be dereferenced
450                 o << ait->name << "(" << ((ait->type.name.find_first_of('*')!=std::string::npos) ? "*" : "" ) << "_" << ait->name << ")";
451             }
452             o << " {}\n";
453         }
454         o << " libt2n::result* operator()();\n"
455         << "};\n";
456     }
457 }
458
459 void output_common_cpp(std::ostream &o, const std::string &group, const std::list<t2n_procedure> &procs, const std::string &common_hpp)
460 {
461     o << "#include \"" << common_hpp << "\"\n"
462     << "#include <boost/serialization/export.hpp>\n"
463     << "\n"
464     << "/* register types with boost serialization */\n";
465     o << "BOOST_CLASS_EXPORT(" << groupClass(group) << ")\n";
466     for (std::list<t2n_procedure>::const_iterator it=procs.begin();it!=procs.end();++it)
467     {
468         o << "BOOST_CLASS_EXPORT("<<it->ret_classname()<<")\n"
469         << "BOOST_CLASS_EXPORT("<<it->cmd_classname()<<")\n";
470     }
471 }
472
473 void output_client_hpp(std::ostream &o, const std::string &group, const std::list<t2n_procedure> &procs)
474 {
475     o << "#include <command_client.hxx>\n";
476
477     o << "class " << groupClass(group) << "_client : public libt2n::command_client\n"
478     << "{\n"
479     << "public:\n"
480     << groupClass(group) << "_client(libt2n::client_connection &_c,\n"
481     << " long long _command_timeout_usec=command_timeout_usec_default,\n"
482     << " long long _hello_timeout_usec=hello_timeout_usec_default)\n"
483     << " : libt2n::command_client(_c,_command_timeout_usec,_hello_timeout_usec)\n"
484     << " {}\n";
485     for (std::list<t2n_procedure>::const_iterator pit=procs.begin();pit!=procs.end();++pit)
486     {
487         o << " " << *pit << ";\n";
488     }
489     o << "};\n";
490 }
491
492 void output_client_cpp(std::ostream &o, const std::string &group, const std::list<t2n_procedure> &procs, const std::string &common_hpp, const std::string &common_cpp, const std::string &client_hpp)
493 {
494     o << "#include \"" << client_hpp << "\"\n"
495     << "#include \"" << common_hpp << "\"\n"
496     << "// fake\n";
497     for (std::list<t2n_procedure>::const_iterator it=procs.begin();it!=procs.end();++it)
498     {
499         o << "libt2n::result* " << it->cmd_classname() << "::operator()() { return NULL; }\n";
500     }
501
502     for (std::list<t2n_procedure>::const_iterator pit=procs.begin();pit!=procs.end();++pit)
503     {
504         o << pit->ret_type << " " << groupClass(group) << "_client::" << pit->name << "(";
505
506         // we need to do this by hand here because we don't want default arguments within the cpp
507         for (t2n_procedure::Args::const_iterator xit=pit->args.begin();xit!=pit->args.end();++xit)
508         {
509             if (xit!=pit->args.begin())
510                 o << ", ";
511             o << xit->type << " " << xit->name;
512         }
513
514         o << ")\n"
515         << "{\n"
516         << " libt2n::result_container rc;\n"
517         << " send_command(new " << pit->cmd_classname() << "(";
518         for (t2n_procedure::Args::const_iterator ait=pit->args.begin();ait!=pit->args.end();++ait)
519         {
520             if (ait!=pit->args.begin()) o << ", ";
521             o << ait->name;
522         }
523         o << "), rc);\n"
524         << " " << pit->ret_classname() << "* res=dynamic_cast<" << pit->ret_classname() << "*>(rc.get_result());\n"
525         << " if (!res) throw libt2n::t2n_communication_error(\"result object of wrong type\");\n";
526         if (pit->hasReturn())
527             o << " return res->get_data();\n";
528         o << "}\n";
529     }
530
531     // include in this compilation unit to ensure the compilation unit is used
532     // see also:
533     // http://www.google.de/search?q=g%2B%2B+static+initializer+in+static+library
534     o << "#include \"" << common_cpp << "\"\n";
535 }
536
537 void output_server_hpp(std::ostream &o, const std::string & /* group */, const std::list<t2n_procedure> &procs, const std::string &common_hpp)
538 {
539     o << "#include \"" << common_hpp << "\"\n";
540
541     // output function declarations
542     for (std::list<t2n_procedure>::const_iterator it=procs.begin();it!=procs.end();++it)
543         o << *it << ";\n";
544 }
545
546 void output_server_cpp(std::ostream &o, const std::string &group, const std::list<t2n_procedure> &procs, const std::string &common_hpp, const std::string &common_cpp)
547 {
548     o << "#include \"" << common_hpp << "\"\n";
549
550     for (std::list<t2n_procedure>::const_iterator it=procs.begin();it!=procs.end();++it)
551     {
552         o << *it << ";\n";
553         o << "libt2n::result* " << it->cmd_classname() << "::operator()() { ";
554
555         if (it->hasReturn())
556             o << "return new " << it->ret_classname() << "(";
557
558         // output function name and args
559         o << it->name << "(";
560         for (t2n_procedure::Args::const_iterator ait=it->args.begin();ait!=it->args.end();++ait)
561         {
562             if (ait!=it->args.begin()) o << ", ";
563             // get pointer
564             if (ait->type.name.find_first_of('*')!=std::string::npos)
565                 o << '&';
566             o << ait->name;
567         }
568
569         if (it->hasReturn())
570             o << "));";
571         else
572             o << "); return new " << it->ret_classname() << "();";
573
574         o << " }\n";
575     }
576     o << "#include \"" << common_cpp << "\"\n";
577 }
578
579 struct header_file : public std::ofstream
580 {
581     header_file(const char* fname) : std::ofstream(fname)
582     {
583         std::cerr << "create header: '" << fname << "'" << std::endl;
584         std::string macro(replace(toupper(fname),'.','_'));
585         *this << "// automatically generated code (generated by libt2n-codegen " << VERSION << ") - do not edit\n" << std::endl;
586         *this << "#ifndef " << macro << "\n"
587         << "#define " << macro << "\n";
588     }
589     ~header_file()
590     {
591         *this << "#endif" << std::endl;
592     }
593 };
594
595 struct cpp_file : public std::ofstream
596 {
597     cpp_file(const char* fname) : std::ofstream(fname)
598     {
599         std::cerr << "create cpp: '" << fname << "'" << std::endl;
600         *this << "// automatically generated code - do not edit\n" << std::endl;
601     }
602 };
603
604 int
605 main(int argc, char* argv[])
606 {
607     // todo: maybe use getopt
608     if ((argc>1)&&(std::string(argv[1])=="--version"))
609     {
610         std::cerr << VERSION << std::endl;
611         return 0;
612     }
613     if (argc < 3)
614     {
615         std::cerr << "Usage: " << argv[0] << "default-group gccxml-file1 gccxml-file2 ... " << std::endl;
616         return 1;
617     }
618
619     try
620     {
621         std::string group(argv[1]);
622         std::list<std::string> xmlfiles;
623         for (int i=2;i<argc;++i)
624             xmlfiles.push_back(argv[i]);
625
626         std::string prefix=group+"_";
627         std::list<t2n_procedure> procedures;
628         for (std::list<std::string>::iterator it=xmlfiles.begin();it!=xmlfiles.end();++it)
629         {
630             std::cerr << "Parse " << *it << std::endl;
631             Parser parser(*it);
632             const std::list<t2n_procedure> &p(parser.get_procedures());
633             std::copy(p.begin(), p.end(), std::back_inserter(procedures));
634         }
635
636         std::cerr << "All procedures:" << std::endl;
637         for (std::list<t2n_procedure>::const_iterator it=procedures.begin();it!=procedures.end();++it)
638             std::cerr << *it << ";" << std::endl;
639
640         std::string common_hpp_fname(prefix+"common.hxx");
641         std::string common_cpp_fname(prefix+"common.cpp");
642         std::string client_hpp_fname(prefix+"client.hxx");
643         std::string client_cpp_fname(prefix+"client.cpp");
644         std::string server_hpp_fname(prefix+"server.hxx");
645         std::string server_cpp_fname(prefix+"server.cpp");
646
647         header_file common_hpp(common_hpp_fname.c_str());
648         common_hpp << "// boost serialization is picky about order of include files => we have to include this one first\n"
649         << "#include \"codegen-stubhead.hxx\"\n"
650         << "#include \"" << group << ".hxx\"\n";
651
652         output_common_hpp(common_hpp, group, procedures);
653
654         cpp_file common_cpp(common_cpp_fname.c_str());
655         output_common_cpp(common_cpp, group, procedures, common_hpp_fname);
656
657         header_file client_hpp(client_hpp_fname.c_str());
658         client_hpp << "// boost serialization is picky about order of include files => we have to include this one first\n"
659         << "#include \"codegen-stubhead.hxx\"\n"
660         << "#include \"" << group << ".hxx\"\n";
661         output_client_hpp(client_hpp, group, procedures);
662
663         cpp_file client_cpp(client_cpp_fname.c_str());
664         output_client_cpp(client_cpp, group, procedures, common_hpp_fname, common_cpp_fname, client_hpp_fname);
665
666         header_file server_hpp(server_hpp_fname.c_str());
667         output_server_hpp(server_hpp, group, procedures, common_hpp_fname);
668
669         cpp_file server_cpp(server_cpp_fname.c_str());
670         output_server_cpp(server_cpp, group, procedures, common_hpp_fname, common_cpp_fname);
671     }
672     catch (const parse_error &e)
673     {
674         std::cerr << e.what() << std::endl;
675         return EXIT_FAILURE;
676     }
677     return EXIT_SUCCESS;
678 }