From: Bruno Haible Date: Sat, 24 Mar 2018 12:16:21 +0000 (+0100) Subject: javacomp-script, javacomp: Add support for Java 10. X-Git-Tag: v1.0~5691 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=8e33103c084e5c7714e821f5fae592b9cbbb4781;p=gnulib.git javacomp-script, javacomp: Add support for Java 10. * m4/javacomp.m4 (gt_JAVACOMP): Accept source-version 10 and target-version 10. * lib/javaversion.h: Update comments. * lib/javacomp.c (default_target_version, SOURCE_VERSION_BOUND, source_version_index, get_goodcode_snippet, get_failcode_snippet, TARGET_VERSION_BOUND, target_version_index, corresponding_classfile_version): Accept source_version 10 and target_version 10. * lib/javacomp.h: Update comments accordingly. --- diff --git a/ChangeLog b/ChangeLog index 01bf93b7e1..02508d69a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2018-03-24 Bruno Haible + + javacomp-script, javacomp: Add support for Java 10. + * m4/javacomp.m4 (gt_JAVACOMP): Accept source-version 10 and + target-version 10. + * lib/javaversion.h: Update comments. + * lib/javacomp.c (default_target_version, SOURCE_VERSION_BOUND, + source_version_index, get_goodcode_snippet, get_failcode_snippet, + TARGET_VERSION_BOUND, target_version_index, + corresponding_classfile_version): Accept source_version 10 and + target_version 10. + * lib/javacomp.h: Update comments accordingly. + 2018-03-24 Bruno Haible javacomp-script, javacomp: Update comments. diff --git a/lib/javacomp.c b/lib/javacomp.c index 1b19f17126..d7100857d7 100644 --- a/lib/javacomp.c +++ b/lib/javacomp.c @@ -104,7 +104,10 @@ default_target_version (void) && java_version_cache[2] >= '1' && java_version_cache[2] <= '8' && java_version_cache[3] == '\0') || (java_version_cache[0] == '9' - && java_version_cache[1] == '\0'))) + && java_version_cache[1] == '\0') + || (java_version_cache[0] == '1' + && java_version_cache[1] == '0' + && java_version_cache[2] == '\0'))) java_version_cache = "1.1"; } return java_version_cache; @@ -113,7 +116,7 @@ default_target_version (void) /* ======================= Source version dependent ======================= */ /* Convert a source version to an index. */ -#define SOURCE_VERSION_BOUND 6 /* exclusive upper bound */ +#define SOURCE_VERSION_BOUND 7 /* exclusive upper bound */ static unsigned int source_version_index (const char *source_version) { @@ -128,6 +131,9 @@ source_version_index (const char *source_version) } else if (source_version[0] == '9' && source_version[1] == '\0') return 5; + else if (source_version[0] == '1' && source_version[1] == '0' + && source_version[2] == '\0') + return 6; error (EXIT_FAILURE, 0, _("invalid source_version argument to compile_java_class")); return 0; } @@ -148,6 +154,8 @@ get_goodcode_snippet (const char *source_version) return "class conftest { void foo () { Runnable r = () -> {}; } }\n"; if (strcmp (source_version, "9") == 0) return "interface conftest { private void foo () {} }\n"; + if (strcmp (source_version, "10") == 0) + return "class conftest { public void m() { var i = new Integer(0); } }\n"; error (EXIT_FAILURE, 0, _("invalid source_version argument to compile_java_class")); return NULL; } @@ -169,6 +177,8 @@ get_failcode_snippet (const char *source_version) if (strcmp (source_version, "1.8") == 0) return "interface conftestfail { private void foo () {} }\n"; if (strcmp (source_version, "9") == 0) + return "class conftestfail { public void m() { var i = new Integer(0); } }\n"; + if (strcmp (source_version, "10") == 0) return NULL; error (EXIT_FAILURE, 0, _("invalid source_version argument to compile_java_class")); return NULL; @@ -177,7 +187,7 @@ get_failcode_snippet (const char *source_version) /* ======================= Target version dependent ======================= */ /* Convert a target version to an index. */ -#define TARGET_VERSION_BOUND 9 /* exclusive upper bound */ +#define TARGET_VERSION_BOUND 10 /* exclusive upper bound */ static unsigned int target_version_index (const char *target_version) { @@ -187,6 +197,9 @@ target_version_index (const char *target_version) return target_version[2] - '1'; else if (target_version[0] == '9' && target_version[1] == '\0') return 8; + else if (target_version[0] == '1' && target_version[1] == '0' + && target_version[2] == '\0') + return 9; error (EXIT_FAILURE, 0, _("invalid target_version argument to compile_java_class")); return 0; } @@ -214,6 +227,8 @@ corresponding_classfile_version (const char *target_version) return 52; if (strcmp (target_version, "9") == 0) return 53; + if (strcmp (target_version, "10") == 0) + return 54; error (EXIT_FAILURE, 0, _("invalid target_version argument to compile_java_class")); return 0; } diff --git a/lib/javacomp.h b/lib/javacomp.h index 53e752d70f..7f33d98253 100644 --- a/lib/javacomp.h +++ b/lib/javacomp.h @@ -32,6 +32,7 @@ 1.7 switch(string) 1.8 lambdas 9 private interface methods + 10 type inference for local variables target_version can be: classfile version: 1.1 45.3 1.2 46.0 @@ -42,6 +43,7 @@ 1.7 51.0 1.8 52.0 9 53.0 + 10 54.0 target_version can also be given as NULL. In this case, the required target_version is determined from the found JVM (see javaversion.h). Specifying target_version is useful when building a library (.jar) that is @@ -53,7 +55,8 @@ - target_version < 1.6 with source_version >= 1.6, or - target_version < 1.7 with source_version >= 1.7, or - target_version < 1.8 with source_version >= 1.8, or - - target_version < 9 with source_version >= 9, + - target_version < 9 with source_version >= 9, or + - target_version < 10 with source_version >= 10, because even Sun's/Oracle's javac doesn't support these combinations. It is redundant to ask for a target_version > source_version, since the smaller target_version = source_version will also always work and newer JVMs diff --git a/lib/javaversion.h b/lib/javaversion.h index 86cbd1a33e..e7ab435151 100644 --- a/lib/javaversion.h +++ b/lib/javaversion.h @@ -26,7 +26,7 @@ extern "C" { /* Return information about the Java version used by execute_java_class(). This is the value of System.getProperty("java.specification.version"). - Some possible values are: 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 9. + Some possible values are: 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 9, 10. Return NULL if the Java version cannot be determined. */ extern char * javaexec_version (void); diff --git a/m4/javacomp.m4 b/m4/javacomp.m4 index 24c0d58c98..c4d650bfdc 100644 --- a/m4/javacomp.m4 +++ b/m4/javacomp.m4 @@ -19,6 +19,7 @@ dnl with or without modifications, as long as this notice is preserved. # 1.7 switch(string) # 1.8 lambdas # 9 private interface methods +# 10 type inference for local variables # Instead of source-version 1.6, use 1.5, since Java 6 did not introduce any # language changes. See # https://docs.oracle.com/javase/8/docs/technotes/guides/language/enhancements.html @@ -33,6 +34,7 @@ dnl with or without modifications, as long as this notice is preserved. # 1.7 51.0 # 1.8 52.0 # 9 53.0 +# 10 54.0 # The classfile version of a .class file can be determined through the "file" # command. More portably, the classfile major version can be determined through # "od -A n -t d1 -j 7 -N 1 classfile". @@ -48,6 +50,7 @@ dnl with or without modifications, as long as this notice is preserved. # 1.7 JDK/JRE 7 # 1.8 JDK/JRE 8 # 9 JDK/JRE 9 +# 10 JDK/JRE 10 # Note: gij >= 3.3 can in some cases handle classes compiled with -target 1.4, # and gij >= 4.1 can in some cases partially handle classes compiled with # -target 1.5, but I have no idea how complete this support is. Similarly, @@ -64,7 +67,8 @@ dnl with or without modifications, as long as this notice is preserved. # - target_version < 1.6 with source_version >= 1.6, or # - target_version < 1.7 with source_version >= 1.7, or # - target_version < 1.8 with source_version >= 1.8, or -# - target_version < 9 with source_version >= 9, +# - target_version < 9 with source_version >= 9, or +# - target_version < 10 with source_version >= 10, # because even Sun's/Oracle's javac doesn't support these combinations. # # It is redundant to ask for a target-version > source-version, since the @@ -118,7 +122,7 @@ changequote([,])dnl CLASSPATH=.${CLASSPATH:+$CLASSPATH_SEPARATOR$CLASSPATH} $CONF_JAVA conftestver 2>&AS_MESSAGE_LOG_FD }` case "$target_version" in - 1.1 | 1.2 | 1.3 | 1.4 | 1.5 | 1.6 | 1.7 | 1.8 | 9) ;; + 1.1 | 1.2 | 1.3 | 1.4 | 1.5 | 1.6 | 1.7 | 1.8 | 9 | 10) ;; null) dnl JDK 1.1.X returns null. target_version=1.1 ;; @@ -142,6 +146,8 @@ changequote([,])dnl 1.8) goodcode='class conftest { void foo () { Runnable r = () -> {}; } }' failcode='interface conftestfail { private void foo () {} }' ;; 9) goodcode='interface conftest { private void foo () {} }' + failcode='class conftestfail { public void m() { var i = new Integer(0); } }' ;; + 10) goodcode='class conftest { public void m() { var i = new Integer(0); } }' failcode='class conftestfail syntax error' ;; *) AC_MSG_ERROR([invalid source-version argument to gt_@&t@JAVACOMP: $source_version]) ;; esac @@ -155,6 +161,7 @@ changequote([,])dnl 1.7) cfversion=51 ;; 1.8) cfversion=52 ;; 9) cfversion=53 ;; + 10) cfversion=54 ;; *) AC_MSG_ERROR([invalid target-version argument to gt_@&t@JAVACOMP: $target_version]) ;; esac # Function to output the classfile version of a file (8th byte) in decimal. @@ -231,6 +238,13 @@ changequote([,])dnl dnl -target 1.7 only possible with -source 1.6/1.7 dnl -target 1.8 only possible with -source 1.6/1.7/1.8 dnl + dnl javac 10: -target 1.6 1.7 1.8 9 10 default: 10 + dnl -source 1.6 1.7 1.8 9 10 default: 10 + dnl -target 1.6 only possible with -source 1.6 + dnl -target 1.7 only possible with -source 1.6/1.7 + dnl -target 1.8 only possible with -source 1.6/1.7/1.8 + dnl -target 9 only possible with -source 1.6/1.7/1.8/9 + dnl dnl The support of jikes for target-version and source-version: dnl dnl jikes 1.14 does not have a way to specify the target-version. It