diff options
Diffstat (limited to 'cpp/src/slice2java/Main.cpp')
-rw-r--r-- | cpp/src/slice2java/Main.cpp | 115 |
1 files changed, 78 insertions, 37 deletions
diff --git a/cpp/src/slice2java/Main.cpp b/cpp/src/slice2java/Main.cpp index 6fe2b12a9b5..198fda6b838 100644 --- a/cpp/src/slice2java/Main.cpp +++ b/cpp/src/slice2java/Main.cpp @@ -15,6 +15,7 @@ #include <Slice/FileTracker.h> #include <Slice/Util.h> #include <Gen.h> +#include <GenCompat.h> #include <iterator> using namespace std; @@ -69,19 +70,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 +111,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; @@ -180,14 +183,14 @@ 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; @@ -208,6 +211,16 @@ compile(const vector<string>& argv) return EXIT_FAILURE; } + if(!compat && (tie || implTie)) + { + getErrorStream() << argv[0] << ": error: TIE classes are only supported with the Java-Compat mapping" << endl; + if(!validate) + { + usage(argv[0]); + } + return EXIT_FAILURE; + } + if(depend && dependxml) { getErrorStream() << argv[0] << ": error: cannot specify both --depend and --depend-xml" << endl; @@ -236,6 +249,13 @@ compile(const vector<string>& argv) out.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,7 +270,7 @@ 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) { @@ -268,8 +288,8 @@ compile(const vector<string>& argv) return EXIT_FAILURE; } - if(!icecpp->printMakefileDependencies(out.os(), depend ? Preprocessor::Java : Preprocessor::SliceXML, includePaths, - "-D__SLICE2JAVA__")) + if(!icecpp->printMakefileDependencies(out.os(), depend ? Preprocessor::Java : Preprocessor::SliceXML, + includePaths, cppOpts)) { out.cleanup(); return EXIT_FAILURE; @@ -292,7 +312,7 @@ compile(const vector<string>& argv) 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) { @@ -322,7 +342,7 @@ 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()) { @@ -343,31 +363,51 @@ compile(const vector<string>& argv) { 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(!checksumClass.empty()) + { + // + // Calculate checksums for the Slice definitions in the unit. + // + ChecksumMap m = createChecksums(p); + copy(m.begin(), m.end(), inserter(checksums, checksums.begin())); + } + if(listGenerated) + { + FileTracker::instance()->setOutput(os.str(), false); + } } - if(implTie) - { - gen.generateImplTie(p); - } - if(!checksumClass.empty()) - { - // - // Calculate checksums for the Slice definitions in the unit. - // - ChecksumMap m = createChecksums(p); - copy(m.begin(), m.end(), inserter(checksums, checksums.begin())); - } - if(listGenerated) + else { - FileTracker::instance()->setOutput(os.str(), false); + Gen gen(argv[0], icecpp->getBaseName(), includePaths, output); + gen.generate(p); + if(impl) + { + gen.generateImpl(p); + } + if(!checksumClass.empty()) + { + // + // Calculate checksums for the Slice definitions in the unit. + // + 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) @@ -418,8 +458,9 @@ 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; return EXIT_FAILURE; |