summaryrefslogtreecommitdiff
path: root/cpp/src/slice2cpp/Main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src/slice2cpp/Main.cpp')
-rw-r--r--cpp/src/slice2cpp/Main.cpp105
1 files changed, 66 insertions, 39 deletions
diff --git a/cpp/src/slice2cpp/Main.cpp b/cpp/src/slice2cpp/Main.cpp
index aa0328c37e9..622273e5658 100644
--- a/cpp/src/slice2cpp/Main.cpp
+++ b/cpp/src/slice2cpp/Main.cpp
@@ -11,6 +11,8 @@
#include <IceUtil/CtrlCHandler.h>
#include <IceUtil/Mutex.h>
#include <IceUtil/MutexPtrLock.h>
+#include <IceUtil/ConsoleUtil.h>
+
#include <Slice/Preprocessor.h>
#include <Slice/FileTracker.h>
#include <Slice/Util.h>
@@ -18,6 +20,7 @@
using namespace std;
using namespace Slice;
+using namespace IceUtilInternal;
namespace
{
@@ -56,32 +59,35 @@ interruptedCallback(int /*signal*/)
void
usage(const string& n)
{
- getErrorStream() << "Usage: " << n << " [options] slice-files...\n";
- getErrorStream() <<
+ consoleErr << "Usage: " << n << " [options] slice-files...\n";
+ consoleErr <<
"Options:\n"
"-h, --help Show this message.\n"
"-v, --version Display the Ice version.\n"
- "--validate Validate command line options.\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"
+ "-d, --debug Print debug messages.\n"
"--depend Generate Makefile dependencies.\n"
"--depend-xml Generate dependencies in XML format.\n"
"--depend-file FILE Write dependencies to FILE instead of standard output.\n"
- "-d, --debug Print debug messages.\n"
- "--ice Allow reserved Ice prefix in Slice identifiers.\n"
- "--underscore Allow underscores in Slice identifiers.\n"
+ "--validate Validate command line options.\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"
+ "--include-dir DIR Use DIR as the header include directory in source files.\n"
+ "--impl-c++11 Generate sample implementations for C++11 mapping.\n"
+ "--impl-c++98 Generate sample implementations for C++98 mapping.\n"
"--checksum Generate checksums for Slice definitions.\n"
- "--stream Generate marshaling support for public stream API.\n"
+ "--dll-export SYMBOL Use SYMBOL for DLL exports\n"
+ " deprecated: use instead [[\"cpp:dll-export:SYMBOL\"]] metadata.\n"
+ "--ice Allow reserved Ice prefix in Slice identifiers\n"
+ " deprecated: use instead [[\"ice-prefix\"]] metadata.\n"
+ "--underscore Allow underscores in Slice identifiers\n"
+ " deprecated: use instead [[\"underscore\"]] metadata.\n"
;
}
@@ -102,7 +108,8 @@ compile(const vector<string>& argv)
opts.addOpt("", "include-dir", IceUtilInternal::Options::NeedArg);
opts.addOpt("", "output-dir", IceUtilInternal::Options::NeedArg);
opts.addOpt("", "dll-export", IceUtilInternal::Options::NeedArg);
- opts.addOpt("", "impl");
+ opts.addOpt("", "impl-c++98");
+ opts.addOpt("", "impl-c++11");
opts.addOpt("", "depend");
opts.addOpt("", "depend-xml");
opts.addOpt("", "depend-file", IceUtilInternal::Options::NeedArg, "");
@@ -110,7 +117,6 @@ compile(const vector<string>& argv)
opts.addOpt("", "ice");
opts.addOpt("", "underscore");
opts.addOpt("", "checksum");
- opts.addOpt("", "stream");
bool validate = find(argv.begin(), argv.end(), "--validate") != argv.end();
vector<string> args;
@@ -120,7 +126,7 @@ compile(const vector<string>& argv)
}
catch(const IceUtilInternal::BadOptException& e)
{
- getErrorStream() << argv[0] << ": " << e.reason << endl;
+ consoleErr << argv[0] << ": " << e.reason << endl;
if(!validate)
{
usage(argv[0]);
@@ -136,7 +142,7 @@ compile(const vector<string>& argv)
if(opts.isSet("version"))
{
- getErrorStream() << ICE_STRING_VERSION << endl;
+ consoleErr << ICE_STRING_VERSION << endl;
return EXIT_SUCCESS;
}
@@ -173,7 +179,9 @@ compile(const vector<string>& argv)
string dllExport = opts.optArg("dll-export");
- bool impl = opts.isSet("impl");
+ bool implCpp98 = opts.isSet("impl-c++98");
+
+ bool implCpp11 = opts.isSet("impl-c++11");
bool depend = opts.isSet("depend");
@@ -189,11 +197,9 @@ compile(const vector<string>& argv)
bool checksum = opts.isSet("checksum");
- bool stream = opts.isSet("stream");
-
if(args.empty())
{
- getErrorStream() << argv[0] << ": error: no input file" << endl;
+ consoleErr << argv[0] << ": error: no input file" << endl;
if(!validate)
{
usage(argv[0]);
@@ -203,7 +209,17 @@ compile(const vector<string>& argv)
if(depend && dependxml)
{
- getErrorStream() << argv[0] << ": error: cannot specify both --depend and --depend-xml" << endl;
+ consoleErr << argv[0] << ": error: cannot specify both --depend and --depend-xml" << endl;
+ if(!validate)
+ {
+ usage(argv[0]);
+ }
+ return EXIT_FAILURE;
+ }
+
+ if(implCpp98 && implCpp11)
+ {
+ consoleErr << argv[0] << ": error: cannot specify both --impl-c++98 and --impl-c++11" << endl;
if(!validate)
{
usage(argv[0]);
@@ -221,10 +237,10 @@ compile(const vector<string>& argv)
IceUtil::CtrlCHandler ctrlCHandler;
ctrlCHandler.setCallback(interruptedCallback);
- DependOutputUtil out(dependFile);
+ ostringstream os;
if(dependxml)
{
- out.os() << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl;
+ os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<dependencies>" << endl;
}
for(vector<string>::const_iterator i = args.begin(); i != args.end(); ++i)
@@ -245,30 +261,37 @@ compile(const vector<string>& argv)
if(cppHandle == 0)
{
- out.cleanup();
return EXIT_FAILURE;
}
UnitPtr u = Unit::createUnit(false, false, ice, underscore);
int parseStatus = u->parse(*i, cppHandle, debug);
+
+ string ext = headerExtension;
+ static const string headerExtPrefix = "cpp:header-ext:";
+ DefinitionContextPtr dc = u->findDefinitionContext(u->topLevelFile());
+ assert(dc);
+ string meta = dc->findMetaData(headerExtPrefix);
+ if(meta.size() > headerExtPrefix.size())
+ {
+ ext = meta.substr(headerExtPrefix.size());
+ }
+
u->destroy();
if(parseStatus == EXIT_FAILURE)
{
- out.cleanup();
return EXIT_FAILURE;
}
- if(!icecpp->printMakefileDependencies(out.os(), depend ? Preprocessor::CPlusPlus : Preprocessor::SliceXML,
- includePaths, "-D__SLICE2CPP__", sourceExtension, headerExtension))
+ if(!icecpp->printMakefileDependencies(os, depend ? Preprocessor::CPlusPlus : Preprocessor::SliceXML,
+ includePaths, "-D__SLICE2CPP__", sourceExtension, ext))
{
- out.cleanup();
return EXIT_FAILURE;
}
if(!icecpp->close())
{
- out.cleanup();
return EXIT_FAILURE;
}
}
@@ -285,7 +308,7 @@ compile(const vector<string>& argv)
if(preprocess)
{
char buf[4096];
- while(fgets(buf, static_cast<int>(sizeof(buf)), cppHandle) != NULL)
+ while(fgets(buf, static_cast<int>(sizeof(buf)), cppHandle) != ICE_NULLPTR)
{
if(fputs(buf, stdout) == EOF)
{
@@ -317,7 +340,7 @@ compile(const vector<string>& argv)
try
{
Gen gen(icecpp->getBaseName(), headerExtension, sourceExtension, extraHeaders, include,
- includePaths, dllExport, output, impl, checksum, stream, ice);
+ includePaths, dllExport, output, implCpp98, implCpp11, checksum, ice);
gen.generate(u);
}
catch(const Slice::FileException& ex)
@@ -326,7 +349,7 @@ compile(const vector<string>& argv)
// cleanup any created files.
FileTracker::instance()->cleanup();
u->destroy();
- getErrorStream() << argv[0] << ": error: " << ex.reason() << endl;
+ consoleErr << argv[0] << ": error: " << ex.reason() << endl;
return EXIT_FAILURE;
}
}
@@ -340,7 +363,6 @@ compile(const vector<string>& argv)
if(interrupted)
{
- out.cleanup();
FileTracker::instance()->cleanup();
return EXIT_FAILURE;
}
@@ -349,7 +371,12 @@ compile(const vector<string>& argv)
if(dependxml)
{
- out.os() << "</dependencies>\n";
+ os << "</dependencies>\n";
+ }
+
+ if(depend || dependxml)
+ {
+ writeDependencies(os.str(), dependFile);
}
return status;
@@ -368,22 +395,22 @@ int main(int argc, char* argv[])
}
catch(const std::exception& ex)
{
- getErrorStream() << args[0] << ": error:" << ex.what() << endl;
+ consoleErr << args[0] << ": error:" << ex.what() << endl;
return EXIT_FAILURE;
}
catch(const std::string& msg)
{
- getErrorStream() << args[0] << ": error:" << msg << endl;
+ consoleErr << args[0] << ": error:" << msg << endl;
return EXIT_FAILURE;
}
catch(const char* msg)
{
- getErrorStream() << args[0] << ": error:" << msg << endl;
+ consoleErr << args[0] << ": error:" << msg << endl;
return EXIT_FAILURE;
}
catch(...)
{
- getErrorStream() << args[0] << ": error:" << "unknown exception" << endl;
+ consoleErr << args[0] << ": error:" << "unknown exception" << endl;
return EXIT_FAILURE;
}
}