Exemple #1
0
  /** Check that the assignment to a local variable is correct. */
  protected void checkLocalAssign(
      FlowGraph graph, LocalAssign a, DataFlowItem dfIn, DataFlowItem dfOut)
      throws SemanticException {
    LocalInstance li = ((Local) a.left()).localInstance();
    if (!currCBI.localDeclarations.contains(li)) {
      throw new SemanticException(
          "Final local variable \"" + li.name() + "\" cannot be assigned to in an inner class.",
          a.position());
    }

    MinMaxInitCount initCount = (MinMaxInitCount) dfOut.initStatus.get(li);

    if (li.flags().isFinal() && InitCount.MANY.equals(initCount.getMax())) {
      throw new SemanticException(
          "variable \"" + li.name() + "\" might already have been assigned to", a.position());
    }
  }
Exemple #2
0
  /** Perform the appropriate flow operations for assignment to a local variable */
  protected Map flowLocalAssign(
      DataFlowItem inItem, FlowGraph graph, LocalAssign a, Set succEdgeKeys) {
    Local l = (Local) a.left();
    Map m = new HashMap(inItem.initStatus);
    MinMaxInitCount initCount = (MinMaxInitCount) m.get(l.localInstance());

    // initcount could be null if the local is defined in the outer
    // class, or if we have not yet seen its declaration (i.e. the
    // local is used in its own initialization)
    if (initCount == null) {
      initCount = new MinMaxInitCount(InitCount.ZERO, InitCount.ZERO);
    }

    initCount = new MinMaxInitCount(initCount.getMin().increment(), initCount.getMax().increment());

    m.put(l.localInstance(), initCount);
    return itemToMap(new DataFlowItem(m), succEdgeKeys);
  }