# HG changeset patch # User Jaroslav Tulach # Date 1356808859 -3600 # Node ID 1679cdfe4172ce935950c3854e2adf98133a2ec3 # Parent 945c799a68121342553ab1ed5807e6ca8fcb1c54 Ability to eliminate debug messages diff -r 945c799a6812 -r 1679cdfe4172 vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Sat Dec 29 20:10:10 2012 +0100 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Sat Dec 29 20:20:59 2012 +0100 @@ -65,6 +65,17 @@ /* protected */ String accessClass(String classOperation) { return classOperation; } + + /** Prints out a debug message. + * + * @param msg the message + * @return true if the message has been printed + * @throws IOException + */ + boolean debug(String msg) throws IOException { + out.append(msg); + return true; + } /** * Converts a given class file to a JavaScript version. @@ -300,7 +311,7 @@ out.append(" case " + i).append(": "); changeInCatch = true; } else { - out.append(" /* " + i).append(" */ "); + debug(" /* " + i + " */ "); } if (changeInCatch && trap.useTry()) { out.append("try {"); @@ -976,7 +987,7 @@ case opc_pop: case opc_pop2: smapper.pop(1); - out.append("/* pop */"); + debug("/* pop */"); break; case opc_dup: { final Variable v = smapper.get(0); @@ -1129,11 +1140,12 @@ Integer.toString(c)); } } - out.append(" //"); - for (int j = prev; j <= i; j++) { - out.append(" "); - final int cc = readByte(byteCodes, j); - out.append(Integer.toString(cc)); + if (debug(" //")) { + for (int j = prev; j <= i; j++) { + out.append(" "); + final int cc = readByte(byteCodes, j); + out.append(Integer.toString(cc)); + } } out.append("\n"); } @@ -1364,7 +1376,7 @@ private void addReference(String cn) throws IOException { if (requireReference(cn)) { - out.append(" /* needs ").append(cn).append(" */"); + debug(" /* needs " + cn + " */"); } } diff -r 945c799a6812 -r 1679cdfe4172 vm/src/main/java/org/apidesign/vm4brwsr/VM.java --- a/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Sat Dec 29 20:10:10 2012 +0100 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Sat Dec 29 20:20:59 2012 +0100 @@ -33,6 +33,11 @@ // uses VMLazy to load dynamic classes VMLazy.init(); } + + @Override + boolean debug(String msg) throws IOException { + return false; + } static void compile(Bck2Brwsr.Resources l, Appendable out, StringArray names) throws IOException { new VM(out).doCompile(l, names);