Ability to eliminate debug messages
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 29 Dec 2012 20:20:59 +0100
changeset 3991679cdfe4172
parent 398 945c799a6812
child 400 5452b9fbd253
Ability to eliminate debug messages
vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java
vm/src/main/java/org/apidesign/vm4brwsr/VM.java
     1.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Sat Dec 29 20:10:10 2012 +0100
     1.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Sat Dec 29 20:20:59 2012 +0100
     1.3 @@ -65,6 +65,17 @@
     1.4      /* protected */ String accessClass(String classOperation) {
     1.5          return classOperation;
     1.6      }
     1.7 +    
     1.8 +    /** Prints out a debug message. 
     1.9 +     * 
    1.10 +     * @param msg the message
    1.11 +     * @return true if the message has been printed
    1.12 +     * @throws IOException 
    1.13 +     */
    1.14 +    boolean debug(String msg) throws IOException {
    1.15 +        out.append(msg);
    1.16 +        return true;
    1.17 +    }
    1.18  
    1.19      /**
    1.20       * Converts a given class file to a JavaScript version.
    1.21 @@ -300,7 +311,7 @@
    1.22                  out.append("    case " + i).append(": ");            
    1.23                  changeInCatch = true;
    1.24              } else {
    1.25 -                out.append("    /* " + i).append(" */ ");
    1.26 +                debug("    /* " + i + " */ ");
    1.27              }
    1.28              if (changeInCatch && trap.useTry()) {
    1.29                  out.append("try {");
    1.30 @@ -976,7 +987,7 @@
    1.31                  case opc_pop:
    1.32                  case opc_pop2:
    1.33                      smapper.pop(1);
    1.34 -                    out.append("/* pop */");
    1.35 +                    debug("/* pop */");
    1.36                      break;
    1.37                  case opc_dup: {
    1.38                      final Variable v = smapper.get(0);
    1.39 @@ -1129,11 +1140,12 @@
    1.40                           Integer.toString(c));
    1.41                  }
    1.42              }
    1.43 -            out.append(" //");
    1.44 -            for (int j = prev; j <= i; j++) {
    1.45 -                out.append(" ");
    1.46 -                final int cc = readByte(byteCodes, j);
    1.47 -                out.append(Integer.toString(cc));
    1.48 +            if (debug(" //")) {
    1.49 +                for (int j = prev; j <= i; j++) {
    1.50 +                    out.append(" ");
    1.51 +                    final int cc = readByte(byteCodes, j);
    1.52 +                    out.append(Integer.toString(cc));
    1.53 +                }
    1.54              }
    1.55              out.append("\n");            
    1.56          }
    1.57 @@ -1364,7 +1376,7 @@
    1.58  
    1.59      private void addReference(String cn) throws IOException {
    1.60          if (requireReference(cn)) {
    1.61 -            out.append(" /* needs ").append(cn).append(" */");
    1.62 +            debug(" /* needs " + cn + " */");
    1.63          }
    1.64      }
    1.65  
     2.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Sat Dec 29 20:10:10 2012 +0100
     2.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/VM.java	Sat Dec 29 20:20:59 2012 +0100
     2.3 @@ -33,6 +33,11 @@
     2.4          // uses VMLazy to load dynamic classes
     2.5          VMLazy.init();
     2.6      }
     2.7 +
     2.8 +    @Override
     2.9 +    boolean debug(String msg) throws IOException {
    2.10 +        return false;
    2.11 +    }
    2.12      
    2.13      static void compile(Bck2Brwsr.Resources l, Appendable out, StringArray names) throws IOException {
    2.14          new VM(out).doCompile(l, names);