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