diff options
Diffstat (limited to 'cpp/src/slice2cpp')
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 40 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.h | 2 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Main.cpp | 43 |
3 files changed, 64 insertions, 21 deletions
diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 9d9d7d4ee4b..66db0d096b1 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -21,11 +21,13 @@ using namespace Slice; using namespace IceUtil; Slice::Gen::Gen(const string& name, const string& base, const string& headerExtension, - const string& sourceExtension, const string& include, const vector<string>& includePaths, - const string& dllExport, const string& dir, bool imp, bool checksum, bool stream) : + const string& sourceExtension, const vector<string>& extraHeaders, const string& include, + const vector<string>& includePaths, const string& dllExport, const string& dir, + bool imp, bool checksum, bool stream) : _base(base), _headerExtension(headerExtension), _sourceExtension(sourceExtension), + _extraHeaders(extraHeaders), _include(include), _includePaths(includePaths), _dllExport(dllExport), @@ -167,6 +169,40 @@ Slice::Gen::generate(const UnitPtr& p) { validateMetaData(p); + // + // Output additional header includes first. + // + vector<string>::const_iterator i; + for(i = _extraHeaders.begin(); i != _extraHeaders.end(); ++i) + { + string hdr = *i; + string guard; + string::size_type pos = hdr.rfind(','); + if(pos != string::npos) + { + hdr = i->substr(0, pos); + guard = i->substr(pos + 1); + } + if(!guard.empty()) + { + C << "\n#ifndef " << guard; + C << "\n#define " << guard; + } + C << "\n#include <"; + if(!_include.empty()) + { + C << _include << '/'; + } + C << hdr << '>'; + if(!guard.empty()) + { + C << "\n#endif"; + } + } + + // + // Output remaining includes. + // C << "\n#include <"; if(_include.size()) { diff --git a/cpp/src/slice2cpp/Gen.h b/cpp/src/slice2cpp/Gen.h index 3f8a1c8dfc9..4d4d2c55531 100644 --- a/cpp/src/slice2cpp/Gen.h +++ b/cpp/src/slice2cpp/Gen.h @@ -24,6 +24,7 @@ public: const std::string&, const std::string&, const std::string&, + const std::vector<std::string>&, const std::string&, const std::vector<std::string>&, const std::string&, @@ -48,6 +49,7 @@ private: std::string _base; std::string _headerExtension; std::string _sourceExtension; + std::vector<std::string> _extraHeaders; std::string _include; std::vector<std::string> _includePaths; std::string _dllExport; diff --git a/cpp/src/slice2cpp/Main.cpp b/cpp/src/slice2cpp/Main.cpp index 8c65493e552..50c91735d5f 100644 --- a/cpp/src/slice2cpp/Main.cpp +++ b/cpp/src/slice2cpp/Main.cpp @@ -20,24 +20,25 @@ usage(const char* n) cerr << "Usage: " << n << " [options] slice-files...\n"; cerr << "Options:\n" - "-h, --help Show this message.\n" - "-v, --version Display the Ice version.\n" - "--header-ext EXT Use EXT instead of the default `h' extension.\n" - "--source-ext EXT Use EXT instead of the default `cpp' extension.\n" - "-DNAME Define NAME as 1.\n" - "-DNAME=DEF Define NAME as DEF.\n" - "-UNAME Remove any definition for NAME.\n" - "-IDIR Put DIR in the include file search path.\n" - "-E Print preprocessor output on stdout.\n" - "--include-dir DIR Use DIR as the header include directory in source files.\n" - "--output-dir DIR Create files in the directory DIR.\n" - "--dll-export SYMBOL Use SYMBOL for DLL exports.\n" - "--impl Generate sample implementations.\n" - "--depend Generate Makefile dependencies.\n" - "-d, --debug Print debug messages.\n" - "--ice Permit `Ice' prefix (for building Ice source code only)\n" - "--checksum Generate checksums for Slice definitions.\n" - "--stream Generate marshaling support for public stream API.\n" + "-h, --help Show this message.\n" + "-v, --version Display the Ice version.\n" + "--header-ext EXT Use EXT instead of the default `h' extension.\n" + "--source-ext EXT Use EXT instead of the default `cpp' extension.\n" + "--add-header HDR[,GUARD] Add #include for HDR (with guard GUARD) to generated source file.\n" + "-DNAME Define NAME as 1.\n" + "-DNAME=DEF Define NAME as DEF.\n" + "-UNAME Remove any definition for NAME.\n" + "-IDIR Put DIR in the include file search path.\n" + "-E Print preprocessor output on stdout.\n" + "--include-dir DIR Use DIR as the header include directory in source files.\n" + "--output-dir DIR Create files in the directory DIR.\n" + "--dll-export SYMBOL Use SYMBOL for DLL exports.\n" + "--impl Generate sample implementations.\n" + "--depend Generate Makefile dependencies.\n" + "-d, --debug Print debug messages.\n" + "--ice Permit `Ice' prefix (for building Ice source code only)\n" + "--checksum Generate checksums for Slice definitions.\n" + "--stream Generate marshaling support for public stream API.\n" ; // Note: --case-sensitive is intentionally not shown here! } @@ -64,6 +65,7 @@ main(int argc, char* argv[]) opts.addOpt("v", "version"); opts.addOpt("", "header-ext", IceUtil::Options::NeedArg, "h"); opts.addOpt("", "source-ext", IceUtil::Options::NeedArg, "cpp"); + opts.addOpt("", "add-header", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); opts.addOpt("D", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); opts.addOpt("U", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); opts.addOpt("I", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat); @@ -104,6 +106,9 @@ main(int argc, char* argv[]) string headerExtension = opts.optArg("header-ext"); string sourceExtension = opts.optArg("source-ext"); + + vector<string> extraHeaders; + extraHeaders = opts.argVec("add-header"); if(opts.isSet("D")) { @@ -208,7 +213,7 @@ main(int argc, char* argv[]) } else { - Gen gen(argv[0], icecpp.getBaseName(), headerExtension, sourceExtension, include, + Gen gen(argv[0], icecpp.getBaseName(), headerExtension, sourceExtension, extraHeaders, include, includePaths, dllExport, output, impl, checksum, stream); if(!gen) { |