6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04
authorsherman
Sat, 26 Jul 2008 20:42:35 -0700
changeset 898 1c4e95595472
parent 897 2a9d890925bb
child 899 40d3416d937a
6681798: (build) CharsetEncoder.java fails to compile in openjdk6 on ubutu 8.04 Summary: replace awk-sed based spp.sh with a java regex based pre-processor Reviewed-by: alanb
jdk/make/java/nio/Makefile
jdk/make/java/nio/genCoder.sh
jdk/make/java/nio/spp.sh
jdk/make/tools/Makefile
jdk/make/tools/spp/Makefile
jdk/make/tools/src/build/tools/spp/Spp.java
--- a/jdk/make/java/nio/Makefile	Fri Jul 25 12:40:22 2008 +0200
+++ b/jdk/make/java/nio/Makefile	Sat Jul 26 20:42:35 2008 -0700
@@ -166,8 +166,8 @@
 # Generate source files
 #
 
-SPP = spp.sh
-SPP_CMD = $(SH) $(SPP)
+SPP_JARFILE = $(BUILDTOOLJARDIR)/spp.jar
+SPP_CMD = $(BOOT_JAVA_CMD) -jar $(SPP_JARFILE)
 
 FILES_genout = $(FILES_gen:%.java=$(GENSRCDIR)/%.java)
 
@@ -183,7 +183,7 @@
 SCH_GEN=$(SNIO_GEN)/ch
 SCS_GEN=$(SNIO_GEN)/cs
 
-sources: $(SPP) $(FILES_genout)
+sources: $(SPP_JARFILE) $(FILES_genout)
 
 #
 # Generated buffer classes
--- a/jdk/make/java/nio/genCoder.sh	Fri Jul 25 12:40:22 2008 +0200
+++ b/jdk/make/java/nio/genCoder.sh	Sat Jul 26 20:42:35 2008 -0700
@@ -53,8 +53,8 @@
     -Dcoding='decoding' \
     -DOtherCoder='Encoder' \
     -DreplTypeName='string' \
-    -DdefaultRepl='"\\\\uFFFD"' \
-    -DdefaultReplName='<tt>"\\\&#92;uFFFD"<\/tt>' \
+    -DdefaultRepl='"\\uFFFD"' \
+    -DdefaultReplName='<tt>"\&#92;uFFFD"<\/tt>' \
     -DreplType='String' \
     -DreplFQType='java.lang.String' \
     -DreplLength='length()' \
@@ -84,7 +84,7 @@
     -DOtherCoder='Decoder' \
     -DreplTypeName='byte array' \
     -DdefaultRepl='new byte[] { (byte)'"'"\\?"'"' }' \
-    -DdefaultReplName='<tt>{<\/tt>\\\&nbsp;<tt>(byte)'"'"\\?"'"'<\/tt>\\\&nbsp;<tt>}<\/tt>' \
+    -DdefaultReplName='<tt>{<\/tt>\&nbsp;<tt>(byte)'"'"\\?"'"'<\/tt>\&nbsp;<tt>}<\/tt>' \
     -DreplType='byte[]' \
     -DreplFQType='byte[]' \
     -DreplLength='length' \
--- a/jdk/make/java/nio/spp.sh	Fri Jul 25 12:40:22 2008 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,165 +0,0 @@
-#! /bin/sh
-
-#
-# Copyright 2000-2001 Sun Microsystems, Inc.  All Rights Reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.  Sun designates this
-# particular file as subject to the "Classpath" exception as provided
-# by Sun in the LICENSE file that accompanied this code.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
-# CA 95054 USA or visit www.sun.com if you need additional information or
-# have any questions.
-#
-
-# SPP: A simple/sed-based/stream preprocessor
-# Mark Reinhold / mr@sun.com
-#
-# Usage: spp [-be] [-Kkey] -Dvar=value ... <in >out
-#
-# Source-file constructs
-#
-#   Meaningful only at beginning of line, works with any number of keys:
-#
-#     #if[key]              Includes text between #if/#end if -Kkey specified,
-#     #else[key]               otherwise changes text to blank lines; key test
-#     #end[key]                may be negated by prefixing !, e.g., #if[!key]
-#
-#     #begin                If -be is specified then lines up to and including
-#     #end                     #begin, and from #end to EOF, are deleted
-#
-#     #warn                 Changed into warning that file is generated
-#
-#     // ##                 Changed into blank line
-#
-#   Meaningful anywhere in line, works only for first two keys:
-#
-#     {#if[key]?yes}        Expands to yes if -Kkey specified
-#     {#if[key]?yes:no}     Expands to yes if -Kkey, otherwise no
-#     {#if[!key]?yes}       Expands to yes if -Kother
-#     {#if[!key]?yes:no}    Expands to yes if -Kother, otherwise no
-#     $var$                 Expands to value if -Dvar=value given
-#
-#     yes, no must not contain whitespace
-#
-# If the environment variable SED is defined, uses that instead of sed
-# If the environment variable NAWK is defined, uses that instead of awk
-#
-
-SED=${SED:-sed}
-NAWK=${NAWK:-awk}
-
-# Map a string of the form -Dvar=value into an appropriate sed command
-#
-subst() {
-  # The first two lines are to avoid the direct use of echo,
-  # which does not treat backslashes consistently across platforms
-  echo '' \
-    | $SED -e "s.*$*" \
-    | $SED -e 's-D\([a-zA-Z_][-a-zA-Z_]*\)=\(.*\)'"s\\\\\$\\1\\\\\$\2gg" \
-           -e 's-D\([a-zA-Z_][-a-zA-Z_]*\)'"s\\\\\$\\1\\\\\$1gg" \
-           -e 's/ //g'
-}
-
-es=
-be=
-keys=
-key1=_1_
-key2=_2_
-while [ $# -gt 0 ]; do
-  case "$1" in
-    -be)
-      be='-e 1,/^#begin$/d -e /^#end$/,$d'
-      ;;
-    -D*)
-      es="$es -e `subst $1`"
-      ;;
-    -K*)
-      nk=`echo $1 | $SED -e 's/-K//'`
-      if [ "x$keys" = x ]; then keys="$nk"; else keys="$keys $nk"; fi
-      if [ "x$key1" = x_1_ ]; then key1="$nk";
-      elif [ "x$key2" = x_2_ ]; then key2="$nk"; fi
-      ;;
-    *)
-      echo "Usage: $0 [-be] [-Kkey] -Dvar=value ... <in >out"
-      exit 1
-      ;;
-  esac
-  shift
-done
-
-text='[-a-zA-Z0-9&;,.<>/#() ]'
-
-$SED $es \
-  -e 's// /g' \
-  -e "s@^#warn .*@// -- This file was mechanically generated: Do not edit! -- //@" \
-  -e 's-// ##.*$--' $be \
-  -e "s/{#if\[$key1\]?\($text*\):\($text*\)}/\1/g" \
-  -e "s/{#if\[!$key1\]?\($text*\):\($text*\)}/\2/g" \
-  -e "s/{#if\[$key1\]?\($text*\)}/\1/g" \
-  -e "s/{#if\[!$key1\]?\($text*\)}//g" \
-  -e "s/{#if\[$key2\]?\($text*\):\($text*\)}/\1/g" \
-  -e "s/{#if\[!$key2\]?\($text*\):\($text*\)}/\2/g" \
-  -e "s/{#if\[$key2\]?\($text*\)}/\1/g" \
-  -e "s/{#if\[!$key2\]?\($text*\)}//g" \
-  -e "s/{#if\[[a-z]*\]?\($text*\):\($text*\)}/\2/g" \
-  -e "s/{#if\[![a-z]*\]?\($text*\):\($text*\)}/\1/g" \
-  -e "s/{#if\[[a-z]*\]?\($text*\)}//g" \
-  -e "s/{#if\[![a-z]*\]?\($text*\)}/\1/g" \
-| $NAWK \
-  'function key(s) {
-     i = match(s, "[a-zA-Z][a-zA-Z]*\\]");
-     if (i > 0) return substr(s, i, RLENGTH - 1);
-     return "XYZZY"; }
-   function neg(s) { return match(s, "!") > 0; }
-   BEGIN {
-     KEYS = "'"$keys"'"
-     n = split(KEYS, ks, "  *");
-     for (i = 1; i <= n; i++) keys[ks[i]] = 1;
-     top = 1; copy[top] = 1 }
-   /^#if\[!?[a-zA-Z][a-zA-Z]*\]/ \
-     { k = key($0);
-       n = neg($0);
-       stack[++top] = k;
-       if ((k in keys) == !n) {
-	 copy[top] = copy[top - 1];
-       } else {
-	 copy[top] = 0;
-       }
-       print ""; next }
-   /^#else\[!?[a-zA-Z][a-zA-Z]*\]/ \
-     { k = key($0);
-       if (stack[top] == k) {
-	 copy[top] = copy[top - 1] && !copy[top];
-       } else {
-	 printf "%d: Mismatched #else key\n", NR | "cat 1>&2";
-	 exit 11
-       }
-       print ""; next }
-   /^#end\[!?[a-zA-Z][a-zA-Z]*\]/ \
-     { k = key($0);
-       if (stack[top] == k) {
-	 top--;
-       } else {
-	 printf "%d: Mismatched #end key\n", NR | "cat 1>&2"
-	 exit 11
-       }
-       print ""; next }
-   /^#/ {
-     printf "%d: Malformed #directive\n", NR | "cat 1>&2"
-     exit 11
-   }
-   { if (copy[top]) print; else print "" }'
--- a/jdk/make/tools/Makefile	Fri Jul 25 12:40:22 2008 +0200
+++ b/jdk/make/tools/Makefile	Sat Jul 26 20:42:35 2008 -0700
@@ -51,6 +51,7 @@
   jdwpgen                   \
   makeclasslist             \
   strip_properties          \
+  spp                       \
   CharsetMapping
 
 all build clean clobber::
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/make/tools/spp/Makefile	Sat Jul 26 20:42:35 2008 -0700
@@ -0,0 +1,45 @@
+#
+# Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Sun designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Sun in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+# CA 95054 USA or visit www.sun.com if you need additional information or
+# have any questions.
+#
+
+#
+# Makefile for build spp tool
+#
+
+BUILDDIR = ../..
+PACKAGE = build.tools.spp
+PRODUCT = tools
+PROGRAM = spp
+include $(BUILDDIR)/common/Defs.gmk
+
+
+BUILDTOOL_SOURCE_ROOT = $(BUILDDIR)/tools/src
+BUILDTOOL_MAIN        = $(PKGDIR)/Spp.java
+
+#
+# Build tool jar rules.
+#
+include $(BUILDDIR)/common/BuildToolJar.gmk
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/make/tools/src/build/tools/spp/Spp.java	Sat Jul 26 20:42:35 2008 -0700
@@ -0,0 +1,189 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+package build.tools.spp;
+
+import java.util.*;
+import java.util.regex.*;
+
+/*
+ * Spp: A simple regex-based stream preprocessor based on Mark Reinhold's
+ *      sed-based spp.sh
+ *
+ * Usage: java build.tools.spp.Spp [-be] [-Kkey] -Dvar=value ... <in >out
+ *
+ * Source-file constructs
+ *
+ *   Meaningful only at beginning of line, works with any number of keys:
+ *
+ *    #if[key]              Includes text between #if/#end if -Kkey specified,
+ *    #else[key]            otherwise changes text to blank lines; key test
+ *    #end[key]             may be negated by prefixing !, e.g., #if[!key]
+ *
+ *    #begin                If -be is specified then lines up to and including
+ *    #end                  #begin, and from #end to EOF, are deleted
+ *
+ *    #warn                 Changed into warning that file is generated
+ *
+ *    // ##                 Changed into blank line
+ *
+ *  Meaningful anywhere in line
+ *
+ *    {#if[key]?yes}        Expands to yes if -Kkey specified
+ *    {#if[key]?yes:no}     Expands to yes if -Kkey, otherwise no
+ *    {#if[!key]?yes}       Expands to yes if -Kother
+ *    {#if[!key]?yes:no}    Expands to yes if -Kother, otherwise no
+ *    $var$                 Expands to value if -Dvar=value given
+ *
+ *    yes, no must not contain whitespace
+ *
+ * @author Xueming Shen
+ */
+
+public class Spp {
+    public static void main(String args[]) throws Exception {
+        Map<String, String> vars = new HashMap<String, String>();
+        Set<String> keys = new HashSet<String>();
+        boolean be = false;
+
+        for (String arg:args) {
+            if (arg.startsWith("-D")) {
+                int i = arg.indexOf('=');
+                vars.put(arg.substring(2, i),arg.substring(i+1));
+            } else if (arg.startsWith("-K")) {
+                keys.add(arg.substring(2));
+            } else if ("-be".equals(arg)) {
+                be = true;
+            } else {
+                System.err.println("Usage: java build.tools.spp.Spp [-be] [-Kkey] -Dvar=value ... <in >out");
+                System.exit(-1);
+            }
+        }
+
+        StringBuffer out = new StringBuffer();
+        new Spp().spp(new Scanner(System.in),
+                      out, "",
+                      keys, vars, be,
+                      false);
+        System.out.print(out.toString());
+    }
+
+    static final String LNSEP = System.getProperty("line.separator");
+    static final String KEY = "([a-zA-Z0-9]+)";
+    static final String VAR = "([a-zA-Z0-9_\\-]+)";
+    static final String TEXT = "([a-zA-Z0-9&;,.<>/#() \\$]+)"; // $ -- hack embedded $var$
+
+    static final int GN_NOT = 1;
+    static final int GN_KEY = 2;
+    static final int GN_YES = 3;
+    static final int GN_NO  = 5;
+    static final int GN_VAR = 6;
+
+    Matcher ifkey = Pattern.compile("^#if\\[(!)?" + KEY + "\\]").matcher("");
+    Matcher elsekey = Pattern.compile("^#else\\[(!)?" + KEY + "\\]").matcher("");
+    Matcher endkey = Pattern.compile("^#end\\[(!)?" + KEY + "\\]").matcher("");
+    Matcher  vardef = Pattern.compile("\\{#if\\[(!)?" + KEY + "\\]\\?" + TEXT + "(:"+ TEXT + ")?\\}|\\$" + VAR + "\\$").matcher("");
+    Matcher  vardef2 = Pattern.compile("\\$" + VAR + "\\$").matcher("");
+
+    void append(StringBuffer buf, String ln,
+                Set<String> keys, Map<String, String> vars) {
+        vardef.reset(ln);
+        while (vardef.find()) {
+            String repl = "";
+            if (vardef.group(GN_VAR) != null)
+                repl = vars.get(vardef.group(GN_VAR));
+            else {
+                boolean test = keys.contains(vardef.group(GN_KEY));
+                if (vardef.group(GN_NOT) != null)
+                    test = !test;
+                repl = test?vardef.group(GN_YES):vardef.group(GN_NO);
+                if (repl == null)
+                    repl = "";
+                else {  // embedded $var$
+                    while (vardef2.reset(repl).find()) {
+                        repl = vardef2.replaceFirst(vars.get(vardef2.group(1)));
+                    }
+                }
+            }
+            vardef.appendReplacement(buf, repl);
+        }
+        vardef.appendTail(buf);
+    }
+
+    // return true if #end[key], #end or EOF reached
+    boolean spp(Scanner in, StringBuffer buf, String key,
+                Set<String> keys, Map<String, String> vars,
+                boolean be, boolean skip) {
+        while (in.hasNextLine()) {
+            String ln = in.nextLine();
+            if (be) {
+                if (ln.startsWith("#begin")) {
+                    buf.setLength(0);      //clean up to this line
+                    continue;
+                }
+                if (ln.equals("#end")) {
+                    while (in.hasNextLine())
+                        in.nextLine();
+                    return true;           //discard the rest to EOF
+                }
+            }
+            if (ifkey.reset(ln).find()) {
+                String k = ifkey.group(GN_KEY);
+                boolean test = keys.contains(k);
+                if (ifkey.group(GN_NOT) != null)
+                    test = !test;
+                buf.append(LNSEP);
+                if (!spp(in, buf, k, keys, vars, be, skip || !test)) {
+                    spp(in, buf, k, keys, vars, be, skip || test);
+                }
+                continue;
+            }
+            if (elsekey.reset(ln).find()) {
+                if (!key.equals(elsekey.group(GN_KEY))) {
+                    throw new Error("Mis-matched #if-else-end at line <" + ln + ">");
+                }
+                buf.append(LNSEP);
+                return false;
+            }
+            if (endkey.reset(ln).find()) {
+                if (!key.equals(endkey.group(GN_KEY))) {
+                    throw new Error("Mis-matched #if-else-end at line <" + ln + ">");
+                }
+                buf.append(LNSEP);
+                return true;
+            }
+            if (ln.startsWith("#warn")) {
+                ln = "// -- This file was mechanically generated: Do not edit! -- //";
+            } else if (ln.trim().startsWith("// ##")) {
+                ln = "";
+            }
+            if (!skip) {
+                append(buf, ln, keys, vars);
+            }
+            buf.append(LNSEP);
+        }
+        return true;
+    }
+}