diff options
Diffstat (limited to 'cpp/src/slice2java/Main.cpp')
-rw-r--r-- | cpp/src/slice2java/Main.cpp | 150 |
1 files changed, 82 insertions, 68 deletions
diff --git a/cpp/src/slice2java/Main.cpp b/cpp/src/slice2java/Main.cpp index c0546e0509d..b32fec75adc 100644 --- a/cpp/src/slice2java/Main.cpp +++ b/cpp/src/slice2java/Main.cpp @@ -11,14 +11,17 @@ #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> #include <Gen.h> +#include <GenCompat.h> #include <iterator> using namespace std; using namespace Slice; +using namespace IceUtilInternal; namespace { @@ -57,8 +60,8 @@ 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" @@ -69,19 +72,21 @@ usage(const string& n) "-IDIR Put DIR in the include file search path.\n" "-E Print preprocessor output on stdout.\n" "--output-dir DIR Create files in the directory DIR.\n" - "--tie Generate TIE classes.\n" + "--tie Generate tie classes.\n" "--impl Generate sample implementations.\n" - "--impl-tie Generate sample TIE implementations.\n" + "--impl-tie Generate sample tie implementations.\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" "--list-generated Emit list of generated files in XML format.\n" "-d, --debug Print debug messages.\n" - "--ice Allow reserved Ice prefix in Slice identifiers.\n" - "--underscore Allow underscores in Slice identifiers.\n" "--checksum CLASS Generate checksums for Slice definitions into CLASS.\n" - "--stream Generate marshaling support for public stream API.\n" "--meta META Define global metadata directive META.\n" + "--compat Use the backward-compatible language mapping.\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" ; } @@ -108,8 +113,8 @@ compile(const vector<string>& argv) opts.addOpt("", "ice"); opts.addOpt("", "underscore"); opts.addOpt("", "checksum", IceUtilInternal::Options::NeedArg); - opts.addOpt("", "stream"); opts.addOpt("", "meta", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); + opts.addOpt("", "compat"); bool validate = find(argv.begin(), argv.end(), "--validate") != argv.end(); vector<string>args; @@ -119,7 +124,7 @@ compile(const vector<string>& argv) } catch(const IceUtilInternal::BadOptException& e) { - getErrorStream() << argv[0] << ": error: " << e.reason << endl; + consoleErr << argv[0] << ": error: " << e.reason << endl; if(!validate) { usage(argv[0]); @@ -135,7 +140,7 @@ compile(const vector<string>& argv) if(opts.isSet("version")) { - getErrorStream() << ICE_STRING_VERSION << endl; + consoleErr << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -180,17 +185,17 @@ compile(const vector<string>& argv) string checksumClass = opts.optArg("checksum"); - bool stream = opts.isSet("stream"); - bool listGenerated = opts.isSet("list-generated"); StringList globalMetadata; vector<string> v = opts.argVec("meta"); copy(v.begin(), v.end(), back_inserter(globalMetadata)); + bool compat = opts.isSet("compat"); + if(args.empty()) { - getErrorStream() << argv[0] << ": error: no input file" << endl; + consoleErr << argv[0] << ": error: no input file" << endl; if(!validate) { usage(argv[0]); @@ -200,7 +205,17 @@ compile(const vector<string>& argv) if(impl && implTie) { - getErrorStream() << argv[0] << ": error: cannot specify both --impl and --impl-tie" << endl; + consoleErr << argv[0] << ": error: cannot specify both --impl and --impl-tie" << endl; + if(!validate) + { + usage(argv[0]); + } + return EXIT_FAILURE; + } + + if(!compat && (tie || implTie)) + { + consoleErr << argv[0] << ": error: TIE classes are only supported with the Java-Compat mapping" << endl; if(!validate) { usage(argv[0]); @@ -210,7 +225,7 @@ 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]); @@ -230,10 +245,17 @@ 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; + } + + vector<string> cppOpts; + cppOpts.push_back("-D__SLICE2JAVA__"); + if(compat) + { + cppOpts.push_back("-D__SLICE2JAVA_COMPAT__"); } for(vector<string>::const_iterator i = args.begin(); i != args.end(); ++i) @@ -250,11 +272,10 @@ compile(const vector<string>& argv) if(depend || dependxml) { PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp->preprocess(false, "-D__SLICE2JAVA__"); + FILE* cppHandle = icecpp->preprocess(false, cppOpts); if(cppHandle == 0) { - out.cleanup(); return EXIT_FAILURE; } @@ -264,42 +285,31 @@ compile(const vector<string>& argv) if(parseStatus == EXIT_FAILURE) { - out.cleanup(); return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(out.os(), depend ? Preprocessor::Java : Preprocessor::SliceXML, includePaths, - "-D__SLICE2JAVA__")) + if(!icecpp->printMakefileDependencies(os, depend ? Preprocessor::Java : Preprocessor::SliceXML, + includePaths, cppOpts)) { - out.cleanup(); return EXIT_FAILURE; } if(!icecpp->close()) { - out.cleanup(); return EXIT_FAILURE; } } else { ostringstream os; - if(listGenerated) - { - Slice::setErrorStream(os); - } - FileTracker::instance()->setSource(*i); PreprocessorPtr icecpp = Preprocessor::create(argv[0], *i, cppArgs); - FILE* cppHandle = icecpp->preprocess(true, "-D__SLICE2JAVA__"); + FILE* cppHandle = icecpp->preprocess(true, cppOpts); if(cppHandle == 0) { - if(listGenerated) - { - FileTracker::instance()->setOutput(os.str(), true); - } + FileTracker::instance()->error(); status = EXIT_FAILURE; break; } @@ -307,7 +317,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) { @@ -322,41 +332,47 @@ compile(const vector<string>& argv) else { UnitPtr p = Unit::createUnit(false, false, ice, underscore, globalMetadata); - int parseStatus = p->parse(*i, cppHandle, debug, Ice); + int parseStatus = p->parse(*i, cppHandle, debug); if(!icecpp->close()) { p->destroy(); + FileTracker::instance()->error(); return EXIT_FAILURE; } if(parseStatus == EXIT_FAILURE) { p->destroy(); - if(listGenerated) - { - FileTracker::instance()->setOutput(os.str(), true); - } status = EXIT_FAILURE; } else { try { - Gen gen(argv[0], icecpp->getBaseName(), includePaths, output); - gen.generate(p, stream); - if(tie) - { - gen.generateTie(p); - } - if(impl) + if(compat) { - gen.generateImpl(p); + GenCompat gen(argv[0], icecpp->getBaseName(), includePaths, output, tie); + gen.generate(p); + if(impl) + { + gen.generateImpl(p); + } + if(implTie) + { + gen.generateImplTie(p); + } } - if(implTie) + else { - gen.generateImplTie(p); + Gen gen(argv[0], icecpp->getBaseName(), includePaths, output); + gen.generate(p); + if(impl) + { + gen.generateImpl(p); + } } + if(!checksumClass.empty()) { // @@ -365,10 +381,6 @@ compile(const vector<string>& argv) ChecksumMap m = createChecksums(p); copy(m.begin(), m.end(), inserter(checksums, checksums.begin())); } - if(listGenerated) - { - FileTracker::instance()->setOutput(os.str(), false); - } } catch(const Slice::FileException& ex) { @@ -377,12 +389,9 @@ compile(const vector<string>& argv) // FileTracker::instance()->cleanup(); p->destroy(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; - if(listGenerated) - { - FileTracker::instance()->setOutput(os.str(), true); - } + consoleErr << argv[0] << ": error: " << ex.reason() << endl; status = EXIT_FAILURE; + FileTracker::instance()->error(); break; } } @@ -395,7 +404,6 @@ compile(const vector<string>& argv) if(interrupted) { - out.cleanup(); // // If the translator was interrupted then cleanup any files we've already created. // @@ -407,7 +415,12 @@ compile(const vector<string>& argv) if(dependxml) { - out.os() << "</dependencies>\n"; + os << "</dependencies>\n"; + } + + if(depend || dependxml) + { + writeDependencies(os.str(), dependFile); } if(status == EXIT_SUCCESS && !checksumClass.empty() && !dependxml) @@ -418,10 +431,11 @@ compile(const vector<string>& argv) } catch(const Slice::FileException& ex) { - // If a file could not be created, then - // cleanup any created files. + // + // If a file could not be created, then cleanup any created files. + // FileTracker::instance()->cleanup(); - getErrorStream() << argv[0] << ": error: " << ex.reason() << endl; + consoleErr << argv[0] << ": error: " << ex.reason() << endl; return EXIT_FAILURE; } } @@ -447,22 +461,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; } } |