copy includes from input file to common_hpp file
authorJens Thiele <jens.thiele@intra2net.com>
Tue, 21 Nov 2006 14:35:21 +0000 (14:35 +0000)
committerJens Thiele <jens.thiele@intra2net.com>
Tue, 21 Nov 2006 14:35:21 +0000 (14:35 +0000)
codegen/codegen-stubhead.hxx
codegen/main.cpp

index 5c330f3..fa9947f 100644 (file)
@@ -6,8 +6,6 @@
 #include <boost/archive/xml_oarchive.hpp>
 #include <boost/archive/xml_iarchive.hpp>
 #include <boost/serialization/serialization.hpp>
-#include <boost/serialization/string.hpp>
-#include <boost/serialization/utility.hpp>
 
 #include <string>
 #include <t2n_exception.hxx>
index a023eaf..f8a2e23 100644 (file)
@@ -295,7 +295,6 @@ used_groups(const std::list<t2n_procedure> &funcs) {
 void output_common_hpp(std::ostream &o, const std::list<t2n_procedure> &procs) {
      std::set<std::string> groups(used_groups(procs));
 
-     o << "#include \"codegen-stubhead.hxx\"\n";
      for (std::set<std::string>::iterator it=groups.begin();it!=groups.end();++it) {
          o << "class cmd_group_" << *it << " : public libt2n::command\n"
            << "{\n"
@@ -476,17 +475,57 @@ struct cpp_file : public std::ofstream
      }
 };
 
+std::list<std::string>
+get_includes(const std::string &fname)
+{
+     // grep "#include" fname
+     std::ifstream in(fname.c_str());
+     std::string line;
+     std::list<std::string> ret;
+     while (std::getline(in,line)) {
+         if (line.find("#include")!=std::string::npos)
+              ret.push_back(line);
+     }
+     return ret;
+}
+
+void
+paste_includes(std::ostream &o, std::list<std::string> &i)
+{
+     o << std::endl
+       << "// copied includes begin" << std::endl;
+     for (std::list<std::string>::const_iterator it=i.begin(); it!=i.end(); ++it)
+         o << *it << std::endl;
+     o << "// copied includes end" << std::endl
+       << std::endl;
+}
+
+struct RemoveGenerated
+{
+     RemoveGenerated(const std::string &_prefix) : prefix(_prefix) {}
+     bool operator()(const std::string &s) const {
+         return (s.find(prefix+"common.hxx")!=std::string::npos);
+     }
+     const std::string &prefix;
+};
+
 int
 main(int argc, char* argv[])
 {
-     if (argc != 3) {
-         std::cerr << "Usage: " << argv[0] << " gccxml-file outputprefix" << std::endl;
+     if (argc != 4) {
+         std::cerr << "Usage: " << argv[0] << " header-file gccxml-file outputprefix" << std::endl;
          return 1;
      }
-     std::string filepath(argv[1]);
-     std::string prefix(argv[2]);
+     std::string headerfile(argv[1]);
+     std::string xmlfile(argv[2]);
+     std::string prefix(argv[3]);
+     std::list<std::string> includes(get_includes(headerfile));
+     remove_if(includes.begin(), includes.end(), RemoveGenerated(prefix));
+     includes.erase(remove_if(includes.begin(), includes.end(), RemoveGenerated(prefix)), includes.end());
+
+     paste_includes(std::cerr, includes);
   
-     Parser parser(filepath);
+     Parser parser(xmlfile);
      std::list<t2n_procedure> procedures(parser.get_procedures());
 
      std::cerr << "Procedures:" << std::endl;
@@ -505,12 +544,18 @@ main(int argc, char* argv[])
      std::string server_cpp_fname(prefix+"server.cpp");
 
      header_file common_hpp(common_hpp_fname.c_str());
+     common_hpp << "#include \"codegen-stubhead.hxx\"\n";
+     paste_includes(common_hpp, includes);
+
      output_common_hpp(common_hpp, procedures);
 
      cpp_file common_cpp(common_cpp_fname.c_str());
      output_common_cpp(common_cpp, procedures, common_hpp_fname);
 
      header_file client_hpp(client_hpp_fname.c_str());
+     // we can't paste the includes before codegen-stubhead.hxx was included
+     // but we also do not want to include codegen-stubhead.hxx in this file
+     //     paste_includes(client_hpp, includes);
      output_client_hpp(client_hpp, procedures);
 
      cpp_file client_cpp(client_cpp_fname.c_str());