From 85106017e48b4dfdec213dc2ff83486edfa7ea10 Mon Sep 17 00:00:00 2001 From: Jens Thiele Date: Tue, 28 Nov 2006 10:30:59 +0000 Subject: [PATCH] put include dependencies into seperate file (one file per command group). simplifies the code --- codegen/main.cpp | 59 ++++++------------------------------------ example-codegen/Makefile.am | 2 +- example-codegen/default.cpp | 12 +-------- example-codegen/default.hxx | 11 ++++++++ example-codegen/other-1.cpp | 15 +---------- example-codegen/other-2.cpp | 16 +----------- example-codegen/other.cpp | 13 --------- example-codegen/other.hxx | 13 +++++++++ 8 files changed, 37 insertions(+), 104 deletions(-) create mode 100644 example-codegen/default.hxx create mode 100644 example-codegen/other.hxx diff --git a/codegen/main.cpp b/codegen/main.cpp index ee70fb1..85c56eb 100644 --- a/codegen/main.cpp +++ b/codegen/main.cpp @@ -496,62 +496,21 @@ struct cpp_file : public std::ofstream } }; -std::list -get_includes(const std::string &fname) -{ - // grep "#include" fname - std::ifstream in(fname.c_str()); - std::string line; - std::list 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 &i) -{ - o << std::endl - << "// copied includes begin" << std::endl; - for (std::list::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 < 4) { - std::cerr << "Usage: " << argv[0] << " export-file default-group gccxml-file1 gccxml-file2 ... " << std::endl; + if (argc < 3) { + std::cerr << "Usage: " << argv[0] << "default-group gccxml-file1 gccxml-file2 ... " << std::endl; return 1; } try{ - std::string exportfile(argv[1]); - std::string group(argv[2]); + std::string group(argv[1]); std::list xmlfiles; - for (unsigned i=3;i includes(get_includes(exportfile)); - 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); - std::list procedures; for (std::list::iterator it=xmlfiles.begin();it!=xmlfiles.end();++it) { Parser parser(*it, group); @@ -577,9 +536,9 @@ main(int argc, char* argv[]) header_file common_hpp(common_hpp_fname.c_str()); common_hpp << "// boost serialization is picky about order of include files => we have to include this one first\n" - << "#include \"codegen-stubhead.hxx\"\n"; - paste_includes(common_hpp, includes); - + << "#include \"codegen-stubhead.hxx\"\n" + << "#include \"" << group << ".hxx\"\n"; + output_common_hpp(common_hpp, procedures); cpp_file common_cpp(common_cpp_fname.c_str()); @@ -587,8 +546,8 @@ main(int argc, char* argv[]) header_file client_hpp(client_hpp_fname.c_str()); client_hpp << "// boost serialization is picky about order of include files => we have to include this one first\n" - << "#include \"codegen-stubhead.hxx\"\n"; - paste_includes(client_hpp, includes); + << "#include \"codegen-stubhead.hxx\"\n" + << "#include \"" << group << ".hxx\"\n"; output_client_hpp(client_hpp, procedures); cpp_file client_cpp(client_cpp_fname.c_str()); diff --git a/example-codegen/Makefile.am b/example-codegen/Makefile.am index d4dae59..db45e0c 100644 --- a/example-codegen/Makefile.am +++ b/example-codegen/Makefile.am @@ -45,7 +45,7 @@ GROUPDEP_FILES = $(foreach i, $(CMDGROUPS), .deps/group_$(i).P) for i in $($*_GROUP); do \ gccxml $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) $${i} -fxml=$${i%*.cpp}.xml; \ done; \ - $(top_builddir)/codegen/codegen $*.cpp $* $($*_GROUP:.cpp=.xml) && touch $@ + $(top_builddir)/codegen/codegen $* $($*_GROUP:.cpp=.xml) && touch $@ # assuming we have gnu make? BUILT_SOURCES = $(foreach i, $(CMDGROUPS), $(foreach j, _common.hxx _common.cpp _client.hxx _client.cpp _server.hxx _server.cpp, $(i)$(j)) ) diff --git a/example-codegen/default.cpp b/example-codegen/default.cpp index 38b936b..7cc63b7 100644 --- a/example-codegen/default.cpp +++ b/example-codegen/default.cpp @@ -1,14 +1,4 @@ -#include -// serialization of string -#include -// serialization of pair -#include - -// std::vector -#include -#include - -#include "default_common.hxx" +#include "default.hxx" //! test pass by copy LIBT2N_EXPORT std::string testfunc(std::string str) diff --git a/example-codegen/default.hxx b/example-codegen/default.hxx new file mode 100644 index 0000000..34e71a5 --- /dev/null +++ b/example-codegen/default.hxx @@ -0,0 +1,11 @@ +#include +// serialization of string +#include +// serialization of pair +#include + +// std::vector +#include +#include + +#include "default_common.hxx" diff --git a/example-codegen/other-1.cpp b/example-codegen/other-1.cpp index 568082d..3d50946 100644 --- a/example-codegen/other-1.cpp +++ b/example-codegen/other-1.cpp @@ -1,17 +1,4 @@ -#include -// serialization of string -#include -// serialization of pair -#include - -// std::vector -#include -#include - -#include "foo.hxx" - -#include "other_common.hxx" - +#include "other.hxx" using namespace std; //! test function overload diff --git a/example-codegen/other-2.cpp b/example-codegen/other-2.cpp index 05ccc4b..f67f0b8 100644 --- a/example-codegen/other-2.cpp +++ b/example-codegen/other-2.cpp @@ -1,18 +1,4 @@ -#include -// serialization of string -#include -// serialization of pair -#include - -// std::vector -#include -#include - -#include "foo.hxx" - -#include "other_common.hxx" - -using namespace std; +#include "other.hxx" //! test own type LIBT2N_EXPORT bool t3(const Foo &foo) diff --git a/example-codegen/other.cpp b/example-codegen/other.cpp index 4121f04..e69de29 100644 --- a/example-codegen/other.cpp +++ b/example-codegen/other.cpp @@ -1,13 +0,0 @@ -#include -// serialization of string -#include -// serialization of pair -#include - -// std::vector -#include -#include - -#include "foo.hxx" - -#include "other_common.hxx" diff --git a/example-codegen/other.hxx b/example-codegen/other.hxx new file mode 100644 index 0000000..4121f04 --- /dev/null +++ b/example-codegen/other.hxx @@ -0,0 +1,13 @@ +#include +// serialization of string +#include +// serialization of pair +#include + +// std::vector +#include +#include + +#include "foo.hxx" + +#include "other_common.hxx" -- 1.7.1