Beispiel #1
0
 private static void toStringTreeHelper(
     ScriptOrFnNode treeTop, Node n, ObjToIntMap printIds, int level, StringBuffer sb) {
   if (Token.printTrees) {
     if (printIds == null) {
       printIds = new ObjToIntMap();
       generatePrintIds(treeTop, printIds);
     }
     for (int i = 0; i != level; ++i) {
       sb.append("    ");
     }
     n.toString(printIds, sb);
     sb.append('\n');
     for (Node cursor = n.getFirstChild(); cursor != null; cursor = cursor.getNext()) {
       if (cursor.getType() == Token.FUNCTION) {
         int fnIndex = cursor.getExistingIntProp(Node.FUNCTION_PROP);
         FunctionNode fn = treeTop.getFunctionNode(fnIndex);
         toStringTreeHelper(fn, fn, null, level + 1, sb);
       } else {
         toStringTreeHelper(treeTop, cursor, printIds, level + 1, sb);
       }
     }
   }
 }
Beispiel #2
0
  private void toString(ObjToIntMap printIds, StringBuffer sb) {
    if (Token.printTrees) {
      sb.append(Token.name(type));
      if (this instanceof StringNode) {
        sb.append(' ');
        sb.append(getString());
      } else if (this instanceof ScriptOrFnNode) {
        ScriptOrFnNode sof = (ScriptOrFnNode) this;
        if (this instanceof FunctionNode) {
          FunctionNode fn = (FunctionNode) this;
          sb.append(' ');
          sb.append(fn.getFunctionName());
        }
        sb.append(" [source name: ");
        sb.append(sof.getSourceName());
        sb.append("] [encoded source length: ");
        sb.append(sof.getEncodedSourceEnd() - sof.getEncodedSourceStart());
        sb.append("] [base line: ");
        sb.append(sof.getBaseLineno());
        sb.append("] [end line: ");
        sb.append(sof.getEndLineno());
        sb.append(']');
      } else if (this instanceof Jump) {
        Jump jump = (Jump) this;
        if (type == Token.BREAK || type == Token.CONTINUE) {
          sb.append(" [label: ");
          appendPrintId(jump.getJumpStatement(), printIds, sb);
          sb.append(']');
        } else if (type == Token.TRY) {
          Node catchNode = jump.target;
          Node finallyTarget = jump.getFinally();
          if (catchNode != null) {
            sb.append(" [catch: ");
            appendPrintId(catchNode, printIds, sb);
            sb.append(']');
          }
          if (finallyTarget != null) {
            sb.append(" [finally: ");
            appendPrintId(finallyTarget, printIds, sb);
            sb.append(']');
          }
        } else if (type == Token.LABEL || type == Token.LOOP || type == Token.SWITCH) {
          sb.append(" [break: ");
          appendPrintId(jump.target, printIds, sb);
          sb.append(']');
          if (type == Token.LOOP) {
            sb.append(" [continue: ");
            appendPrintId(jump.getContinue(), printIds, sb);
            sb.append(']');
          }
        } else {
          sb.append(" [target: ");
          appendPrintId(jump.target, printIds, sb);
          sb.append(']');
        }
      } else if (type == Token.NUMBER) {
        sb.append(' ');
        sb.append(getDouble());
      } else if (type == Token.TARGET) {
        sb.append(' ');
        appendPrintId(this, printIds, sb);
      }
      if (lineno != -1) {
        sb.append(' ');
        sb.append(lineno);
      }

      for (PropListItem x = propListHead; x != null; x = x.next) {
        int type = x.type;
        sb.append(" [");
        sb.append(propToString(type));
        sb.append(": ");
        String value;
        switch (type) {
          case TARGETBLOCK_PROP: // can't add this as it recurses
            value = "target block property";
            break;
          case LOCAL_BLOCK_PROP: // can't add this as it is dull
            value = "last local block";
            break;
          case ISNUMBER_PROP:
            switch (x.intValue) {
              case BOTH:
                value = "both";
                break;
              case RIGHT:
                value = "right";
                break;
              case LEFT:
                value = "left";
                break;
              default:
                throw Kit.codeBug();
            }
            break;
          case SPECIALCALL_PROP:
            switch (x.intValue) {
              case SPECIALCALL_EVAL:
                value = "eval";
                break;
              case SPECIALCALL_WITH:
                value = "with";
                break;
              default:
                // NON_SPECIALCALL should not be stored
                throw Kit.codeBug();
            }
            break;
          default:
            Object obj = x.objectValue;
            if (obj != null) {
              value = obj.toString();
            } else {
              value = String.valueOf(x.intValue);
            }
            break;
        }
        sb.append(value);
        sb.append(']');
      }
    }
  }