diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/slice2cppe/Gen.cpp | 69 | ||||
-rw-r--r-- | cpp/src/slice2cppe/Gen.h | 2 | ||||
-rw-r--r-- | cpp/src/slice2freeze/Main.cpp | 34 |
3 files changed, 70 insertions, 35 deletions
diff --git a/cpp/src/slice2cppe/Gen.cpp b/cpp/src/slice2cppe/Gen.cpp index 5808126ef91..0e160b0c096 100644 --- a/cpp/src/slice2cppe/Gen.cpp +++ b/cpp/src/slice2cppe/Gen.cpp @@ -187,40 +187,8 @@ 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"; - } - } + writeExtraHeaders(C); - // - // Output remaining includes. - // C << "\n#include <"; if(_include.size()) { @@ -325,7 +293,9 @@ Slice::Gen::generate(const UnitPtr& p) } implH << _base << ".h>"; - implC << "#include <"; + writeExtraHeaders(implC); + + implC << "\n#include <"; if(_include.size()) { implC << _include << '/'; @@ -337,6 +307,37 @@ Slice::Gen::generate(const UnitPtr& p) } } +void +Slice::Gen::writeExtraHeaders(Output& out) +{ + for(vector<string>::const_iterator 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()) + { + out << "\n#ifndef " << guard; + out << "\n#define " << guard; + } + out << "\n#include <"; + if(!_include.empty()) + { + out << _include << '/'; + } + out << hdr << '>'; + if(!guard.empty()) + { + out << "\n#endif"; + } + } +} + Slice::Gen::TypesVisitor::TypesVisitor(Output& h, Output& c, const string& dllExport) : H(h), C(c), _dllExport(dllExport), _doneStaticSymbol(false) { diff --git a/cpp/src/slice2cppe/Gen.h b/cpp/src/slice2cppe/Gen.h index 5dd2ef6bced..f1fe0778070 100644 --- a/cpp/src/slice2cppe/Gen.h +++ b/cpp/src/slice2cppe/Gen.h @@ -44,6 +44,8 @@ public: private: + void writeExtraHeaders(::IceUtil::Output&); + ::IceUtil::Output H; ::IceUtil::Output C; diff --git a/cpp/src/slice2freeze/Main.cpp b/cpp/src/slice2freeze/Main.cpp index 22bce317e9f..10d308cb595 100644 --- a/cpp/src/slice2freeze/Main.cpp +++ b/cpp/src/slice2freeze/Main.cpp @@ -54,6 +54,8 @@ usage(const char* 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]\n" + " 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" @@ -979,6 +981,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); @@ -1019,6 +1022,8 @@ main(int argc, char* argv[]) headerExtension = opts.optArg("header-ext"); sourceExtension = opts.optArg("source-ext"); + vector<string> extraHeaders = opts.argVec("add-header"); + if(opts.isSet("D")) { vector<string> optargs = opts.argVec("D"); @@ -1367,7 +1372,34 @@ main(int argc, char* argv[]) } printHeader(C); printFreezeTypes(C, dicts, indices); - + + for(vector<string>::const_iterator 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"; + } + } + string s = fileH; transform(s.begin(), s.end(), s.begin(), ToIfdef()); H << "\n#ifndef __" << s << "__"; |