Exemplo n.º 1
0
 @Override
 protected void onSaveInstanceState(Bundle outState) {
   outState.putParcelableArray(
       INSTANCE_STATE_BACK_STACK_FILES,
       mBackSelectFileFragments.toArray(new JsonDirectory.JsonFileDir[0]));
   outState.putParcelableArray(
       INSTANCE_STATE_BACK_STACK_TORRENTS,
       mBackTorrentFragments.toArray(new JsonTorrent.JsonTorrentResult[0]));
   super.onSaveInstanceState(outState);
 }
  /**
   * -- before stack 00: jump 04 (jump to 04 on jumpCondition) 01: 02: 03: -- after stack (if jump
   * not succeeded) 04:
   *
   * @param jumpCondition
   * @param beforeStack = jump executed stack
   * @param afterStack = jump NOT executed stack
   * @return a new copy of stack
   */
  protected Stack<Operation> handleUnequalStack(
      Operation jumpCondition, Stack<Operation> beforeStack, Stack<Operation> afterStack) {
    boolean equalStacks = Arrays.equals(beforeStack.toArray(), afterStack.toArray());
    if (equalStacks) {
      return copyExecutionStack(afterStack);
    }

    logger.debug("Unequal stacks");

    // Handle only equal size stacks
    if (beforeStack.size() == afterStack.size()) {
      return handleEqualSizeStack(jumpCondition, beforeStack, afterStack);
    } else {
      return handleUnEqualSizeStack(jumpCondition, beforeStack, afterStack);
    }
  }
Exemplo n.º 3
0
 @Override
 protected void onSaveInstanceState(Bundle outState) {
   super.onSaveInstanceState(outState);
   outState.putString("result", result);
   outState.putChar("lastOp", lastOp);
   outState.putBoolean("isInEquals", isInEquals);
   outState.putSerializable("stack", stack.toArray(new String[stack.size()]));
 }
Exemplo n.º 4
0
  private String errmsg(
      String err,
      int fno,
      char opcode,
      LineInfo li,
      boolean[] pt,
      boolean[] tt,
      boolean[] lt,
      int pshift,
      int tshift,
      int lshift,
      Stack<Boolean> stack,
      int tc) {

    String errm = "";
    if (!err.startsWith(ChatColor.RED + "Detailed Error Message: ")) {
      errm += ChatColor.RED + "Detailed Error Message: " + ChatColor.RESET + err + "\n";
      errm +=
          ChatColor.RED
              + "Persistent Variable Table: \n "
              + ChatColor.RESET
              + dumpStateText(pt)
              + "\n";
      errm += ChatColor.RED + " - Shift: " + ChatColor.RESET + pshift + "\n";
      errm +=
          ChatColor.RED + "Temp Variable Table: \n " + ChatColor.RESET + dumpStateText(tt) + "\n";
      errm += ChatColor.RED + " - Shift: " + ChatColor.RESET + tshift + "\n";
    } else {
      errm += err + "\n";
    }
    errm += ChatColor.RED + "====\n";
    if (tc > 0) {
      errm += "(" + tc + " tail call" + (tc > 1 ? "s" : "") + " omitted)\n====\n";
    }
    errm +=
        ChatColor.RED
            + "Location: "
            + ChatColor.RESET
            + "Opcode "
            + opcode
            + " at line "
            + li.line
            + ", column "
            + li.col
            + " in function #"
            + fno
            + "\n";
    errm +=
        ChatColor.RED + "Local Variable Table: \n " + ChatColor.RESET + dumpStateText(lt) + "\n";
    errm += ChatColor.RED + " - Shift: " + ChatColor.RESET + lshift + "\n";
    errm +=
        ChatColor.RED
            + "Function Stack: "
            + ChatColor.RESET
            + dumpStateText(stack.toArray(new Boolean[stack.size()]));
    return errm;
  }
Exemplo n.º 5
0
  public void visualizarStack() {
    System.out.println("\nStack:\t");
    for (Object obj : stackNodes.toArray()) {

      System.out.print(((MyDefaultMutableTreeNode) obj).toString() + " | ");
    }
    System.out.println(
        "\n---------------------------------------------------------------------------\n");
  }
 /*
  * (non-Javadoc)
  *
  * @see org.walkmod.javalang.visitors.VoidVisitorAdapter#visit(org.walkmod.javalang.ast.body.Parameter,
  * java.lang.Object)
  */
 @SuppressWarnings("unchecked")
 @Override
 public void visit(Parameter n, VisitorContext arg) {
   Map<String, Object> m = variablesMap.get(classStack.peek());
   Object[] strings = methodStack.toArray();
   for (int i = 0; i < methodStack.size(); i++) {
     m = (Map<String, Object>) m.get(strings[i]);
   }
   m.put(n.getId().getName(), getActualType(n.getType()));
   super.visit(n, arg);
 }
Exemplo n.º 7
0
  private static String[] credit_card_number(String[] prefixList, int length, int howMany) {

    Stack<String> result = new Stack<String>();
    for (int i = 0; i < howMany; i++) {
      int randomArrayIndex = (int) Math.floor(Math.random() * prefixList.length);
      String ccnumber = prefixList[randomArrayIndex];
      result.push(completed_number(ccnumber, length));
    }

    return result.toArray(new String[result.size()]);
  }
 /*
  * (non-Javadoc)
  *
  * @see
  * org.walkmod.javalang.visitors.VoidVisitorAdapter#visit(org.walkmod.javalang.ast.expr.VariableDeclarationExpr,
  * java.lang.Object)
  */
 @SuppressWarnings("unchecked")
 @Override
 public void visit(VariableDeclarationExpr n, VisitorContext arg) {
   Map<String, Object> m = variablesMap.get(classStack.peek());
   Object[] strings = methodStack.toArray();
   for (int i = 0; i < strings.length; i++) {
     m = (Map<String, Object>) m.get(strings[i]);
   }
   String type = getActualType(n.getType());
   List<VariableDeclarator> lDeclarators = n.getVars();
   for (VariableDeclarator declarator : lDeclarators) {
     m.put(declarator.getId().getName(), type);
   }
   super.visit(n, arg);
 }
Exemplo n.º 9
0
  public String getTraceback(SourceRange sourceRange) {

    SourceLocation[] locations = templates.toArray(new SourceLocation[templates.size()]);

    StringBuilder sb = new StringBuilder();
    sb.append(">>> call stack trace \n");
    sb.append(">>> ");
    sb.append((new SourceLocation(currentTemplate, sourceRange)).toString());
    sb.append("\n");
    for (int i = locations.length - 1; i >= 0; i--) {
      sb.append(">>> ");
      sb.append(locations[i].toString());
      sb.append("\n");
    }
    sb.append(">>> ====================\n\n");

    return sb.toString();
  }
 /*
  * (non-Javadoc)
  *
  * @see org.walkmod.javalang.visitors.VoidVisitorAdapter#visit(org.walkmod.javalang.ast.body.MethodDeclaration,
  * java.lang.Object)
  */
 @SuppressWarnings("unchecked")
 @Override
 public void visit(MethodDeclaration n, VisitorContext arg) {
   Map<String, Object> m = variablesMap.get(classStack.peek());
   if (!methodStack.isEmpty()) {
     Object[] strings = methodStack.toArray();
     for (int i = 0; i < methodStack.size(); i++) {
       if (m.containsKey(strings[i])) {
         m = (Map<String, Object>) m.get(strings[i]);
       }
     }
   }
   String name = getUniqueMethodName(n);
   Map<String, String> temp = new HashMap<String, String>();
   temp.put("this", getActualType(n.getType()));
   m.put(name, temp);
   methodStack.push(name);
   super.visit(n, arg);
   m.remove(methodStack.pop());
 }
 /**
  * Gets the variable type.
  *
  * @param variableName the variable name
  * @return the variable type
  */
 @SuppressWarnings("rawtypes")
 private String getVariableType(String variableName) {
   if (classStack.isEmpty()) {
     return null;
   }
   Map classData = variablesMap.get(classStack.peek());
   if (!methodStack.isEmpty()) {
     Object[] strings = methodStack.toArray();
     for (int i = 0; i < strings.length; i++) {
       Map methodData = classData;
       for (int i1 = 0; i1 < strings.length - i; i1++) {
         methodData = (Map) methodData.get(strings[i1]);
       }
       if (methodData.containsKey(variableName)) {
         return (String) methodData.get(variableName);
       }
     }
   }
   return (String) classData.get(variableName);
 }
Exemplo n.º 12
0
  public void addNonTerminal(Symbol nonTerminalSymbol, int childs) {

    MyDefaultMutableTreeNode node = newNode(nonTerminalSymbol);

    int y = childs;

    int z = stackNodes.size();

    while (childs > 0) {

      node.add((MutableTreeNode) stackNodes.toArray()[z - childs]);

      childs--;
    }

    while (y > 0) {

      stackNodes.pop();

      y--;
    }

    stackNodes.push(node);
  }
 private String subtreeAsText(PopsIONode node, String s, Stack<Integer> x, int depth, String b) {
   Integer[] y = x.toArray(new Integer[x.size()]);
   StringBuffer indent = new StringBuffer();
   for (int i = 0; i < depth; i++) {
     indent.append("  ");
   }
   for (int i = 0; i < y.length; i++) {
     indent.replace(2 * y[i], 2 * y[i] + 1, "|");
   }
   if (b.length() > 0) {
     indent.replace(indent.length() - b.length(), indent.length(), b);
   }
   s += indent;
   s += node.asText(indent.length());
   s += System.getProperty("line.separator");
   String subs = "";
   if (node.lft >= 0) {
     x.push(depth);
     subs += subtreeAsText(pionodes[node.lft], "", x, depth + 1, "-");
     x.pop();
     subs += subtreeAsText(pionodes[node.rgt], "", x, depth + 1, "`-");
   }
   return s + subs;
 }
Exemplo n.º 14
0
 /**
  * @deprecated Only used when the intention is to draw the shapes using the stencil buffer..
  * @return the reverse move to vertices
  */
 public Vertex[] getReverseMoveToVertices() {
   return (Vertex[]) reverseMoveToStack.toArray(new Vertex[reverseMoveToStack.size()]);
 }
Exemplo n.º 15
0
  @Override
  public RenderState extract(final Stack<? extends RenderState> stack, final Spatial spat) {
    if (spat == null) {
      return stack.peek();
    }

    final LightCombineMode mode = spat.getLightCombineMode();

    final Mesh mesh = (Mesh) spat;
    LightState lightState = mesh.getLightState();
    if (lightState == null) {
      lightState = new LightState();
      mesh.setLightState(lightState);
    }

    lightState.detachAll();

    if (mode == LightCombineMode.Replace || (mode != LightCombineMode.Off && stack.size() == 1)) {
      // todo: use dummy state if off?

      final LightState copyLightState = (LightState) stack.peek();
      copyLightState(copyLightState, lightState);
    } else {
      // accumulate the lights in the stack into a single LightState object
      final Object states[] = stack.toArray();
      boolean foundEnabled = false;
      switch (mode) {
        case CombineClosest:
        case CombineClosestEnabled:
          for (int iIndex = states.length - 1; iIndex >= 0; iIndex--) {
            final LightState pkLState = (LightState) states[iIndex];
            if (!pkLState.isEnabled()) {
              if (mode == LightCombineMode.CombineClosestEnabled) {
                break;
              }

              continue;
            }

            foundEnabled = true;
            copyLightState(pkLState, lightState);
          }
          break;
        case CombineFirst:
          for (int iIndex = 0, max = states.length; iIndex < max; iIndex++) {
            final LightState pkLState = (LightState) states[iIndex];
            if (!pkLState.isEnabled()) {
              continue;
            }

            foundEnabled = true;
            copyLightState(pkLState, lightState);
          }
          break;
        case Off:
          break;
      }
      lightState.setEnabled(foundEnabled);
    }

    return lightState;
  }