From e6cbf802f2977d06854a65036a860740e24d3151 Mon Sep 17 00:00:00 2001 From: Mark Spruiell Date: Tue, 23 Aug 2016 17:28:35 -0700 Subject: Major changes in Java: - Moved existing Java mapping sources to java-compat subdirectory - Added new "Java 8" mapping in java subdirectory - Significant features of Java 8 mapping: - All classes in com.zeroc package (e.g., com.zeroc.Ice.Communicator) - New AMI mapping that uses java.util.concurrent.CompletableFuture - New AMD mapping that uses java.util.concurrent.CompletionStage - New mapping for out parameters - "holder" types have been eliminated - New mapping for optional types that uses JDK classes from java.util (e.g., java.util.Optional) - "TIE" classes are no longer supported or necessary; servant classes now only need to implement a generated interface - Moved IceGrid GUI to new mapping - The "Java Compat" mapping is provided only for backward compatibility to ease migration to Ice 3.7. The Slice compiler supports a new --compat option to generate code for this mapping. However, users are encouraged to migrate to the new mapping as soon as possible. --- cpp/src/slice2java/Main.cpp | 104 ++++++++++++++++++++++++++++++++------------ 1 file changed, 75 insertions(+), 29 deletions(-) (limited to 'cpp/src/slice2java/Main.cpp') diff --git a/cpp/src/slice2java/Main.cpp b/cpp/src/slice2java/Main.cpp index 7b9737d98a2..aba738cfaa3 100644 --- a/cpp/src/slice2java/Main.cpp +++ b/cpp/src/slice2java/Main.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include using namespace std; @@ -81,6 +82,7 @@ usage(const char* n) "--underscore Allow underscores in Slice identifiers.\n" "--checksum CLASS Generate checksums for Slice definitions into CLASS.\n" "--meta META Define global metadata directive META.\n" + "--compat Use the backward-compatible language mapping.\n" ; } @@ -108,7 +110,7 @@ compile(int argc, char* argv[]) opts.addOpt("", "underscore"); opts.addOpt("", "checksum", IceUtilInternal::Options::NeedArg); opts.addOpt("", "meta", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); - + opts.addOpt("", "compat"); bool validate = false; for(int i = 0; i < argc; ++i) @@ -193,6 +195,8 @@ compile(int argc, char* argv[]) vector 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; @@ -213,6 +217,16 @@ compile(int argc, char* 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; @@ -241,6 +255,13 @@ compile(int argc, char* argv[]) out.os() << "\n" << endl; } + vector cppOpts; + cppOpts.push_back("-D__SLICE2JAVA__"); + if(compat) + { + cppOpts.push_back("-D__SLICE2JAVA_COMPAT__"); + } + for(vector::const_iterator i = args.begin(); i != args.end(); ++i) { // @@ -255,7 +276,7 @@ compile(int argc, char* 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) { @@ -273,8 +294,8 @@ compile(int argc, char* 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; @@ -297,7 +318,7 @@ compile(int argc, char* 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) { @@ -348,31 +369,55 @@ compile(int argc, char* argv[]) { try { - Gen gen(argv[0], icecpp->getBaseName(), includePaths, output); - gen.generate(p); - if(tie) - { - gen.generateTie(p); - } - if(impl) + if(compat) { - gen.generateImpl(p); + GenCompat gen(argv[0], icecpp->getBaseName(), includePaths, output); + gen.generate(p); + if(tie) + { + gen.generateTie(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) @@ -423,8 +468,9 @@ compile(int argc, char* 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; -- cgit v1.2.3