Exemple #1
0
    private void determineTypesUpto(int end) {
      Type[] environment = environments[0];

      for (int i = position; i < end; ++i) {
        Code code = stmts.get(i).code;
        if (code instanceof Code.Label) {
          Code.Label label = (Code.Label) code;
          Type[] nEnv = cache.get(label.label);
          environment = join(environment, nEnv);
        } else if (code instanceof Code.AbstractAssignable) {
          Code.AbstractAssignable c = (Code.AbstractAssignable) code;
          environment = Arrays.copyOf(environment, environment.length);
          environment[c.target] = c.assignedType();
        } else if (code instanceof Code.Goto) {
          Code.Goto gto = (Code.Goto) code;
          cache.put(gto.target, environment);
          environment = null;
        } else if (code instanceof Code.If) {
          Code.If gto = (Code.If) code;
          cache.put(gto.target, environment);
        } else if (code instanceof Code.IfIs) {
          Code.IfIs gto = (Code.IfIs) code;
          Type[] trueEnv = Arrays.copyOf(environment, environment.length);
          trueEnv[gto.operand] = Type.intersect(trueEnv[gto.operand], gto.rightOperand);
          cache.put(gto.target, trueEnv);
          environment[gto.operand] =
              Type.intersect(trueEnv[gto.operand], Type.Negation(gto.rightOperand));
        } else if (code instanceof Code.Switch) {
          Code.Switch sw = (Code.Switch) code;
          for (Pair<Constant, String> c : sw.branches) {
            cache.put(c.second(), environment);
          }
          cache.put(sw.defaultTarget, environment);
        } else if (code instanceof Code.ForAll) {
          // FIXME: what this need to do is update the type for the
          // index variable, and then invalidate it afterwards.
          throw new RuntimeException("need to implement for-all loop!");
        } else if (code instanceof Code.Return || code instanceof Code.Throw) {
          environment = null;
        }

        environments[i] = environment;
      }
    }
Exemple #2
0
 /** Return the number of bytecodes in this block. */
 public int size() {
   return stmts.size();
 }
Exemple #3
0
 /**
  * Remove the bytecode at a given position in this block. Those bytecodes after this position will
  * then be shifted up one position in the block.
  *
  * @param index --- index of bytecode to remove.
  */
 public void remove(int index) {
   stmts.remove(index);
 }
Exemple #4
0
 /**
  * Replace the bytecode at a given position in this block with another. It is assumed that the
  * bytecode employs the same environment as this block.
  *
  * @param index --- position of bytecode to replace.
  * @param code --- bytecode to replace with.
  * @param attributes
  */
 public void replace(int index, Code code, Attribute... attributes) {
   stmts.set(index, new Entry(code, attributes));
 }
Exemple #5
0
 /**
  * Replace the bytecode at a given position in this block with another. It is assumed that the
  * bytecode employs the same environment as this block.
  *
  * @param index --- position of bytecode to replace.
  * @param code --- bytecode to replace with.
  * @param attributes
  */
 public void replace(int index, Code code, Collection<Attribute> attributes) {
   stmts.set(index, new Entry(code, attributes));
 }
Exemple #6
0
 /**
  * Insert a bytecode at a given position in this block. It is assumed that the bytecode employs
  * the same environment as this block. The bytecode at the given position (and any after it) are
  * shifted one position down.
  *
  * @param index --- position to insert at.
  * @param code --- bytecode to insert at the given position.
  * @param attributes
  */
 public void insert(int index, Code code, Attribute... attributes) {
   stmts.add(index, new Entry(code, attributes));
 }
Exemple #7
0
 /**
  * Insert a bytecode at a given position in this block. It is assumed that the bytecode employs
  * the same environment as this block. The bytecode at the given position (and any after it) are
  * shifted one position down.
  *
  * @param index --- position to insert at.
  * @param code --- bytecode to insert at the given position.
  * @param attributes
  */
 public void insert(int index, Code code, Collection<Attribute> attributes) {
   stmts.add(index, new Entry(code, attributes));
 }
Exemple #8
0
 /**
  * Append a bytecode onto the end of this block. It is assumed that the bytecode employs the same
  * environment as this block.
  *
  * @param code --- bytecode to append
  * @param attributes --- attributes associated with bytecode.
  */
 public void append(Code code, Collection<Attribute> attributes) {
   stmts.add(new Entry(code, attributes));
 }
Exemple #9
0
 /**
  * Append a bytecode onto the end of this block. It is assumed that the bytecode employs the same
  * environment as this block.
  *
  * @param code --- bytecode to append
  * @param attributes --- attributes associated with bytecode.
  */
 public void append(Code code, Attribute... attributes) {
   stmts.add(new Entry(code, attributes));
 }
Exemple #10
0
 public void append(Block.Entry entry) {
   stmts.add(new Entry(entry.code, entry.attributes()));
 }
Exemple #11
0
 public Iterator<Entry> iterator() {
   return stmts.iterator();
 }
Exemple #12
0
 /**
  * Return block entry at the given position.
  *
  * @param index --- position to return entry of.
  * @return
  */
 public Entry get(int index) {
   return stmts.get(index);
 }