Exemple #1
0
  @Override
  public SStmCG caseAClassInvariantStm(AClassInvariantStm node, IRInfo question)
      throws AnalysisException {
    List<PExp> exps = new LinkedList<PExp>();

    for (PDefinition d : node.getInvDefs()) {
      if (!(d instanceof AClassInvariantDefinition)) {
        Logger.getLog()
            .printErrorln(
                "Expected class invariant definition in '"
                    + this.getClass().getName()
                    + "'. Got: "
                    + d);
        return null;
      }

      AClassInvariantDefinition invDef = (AClassInvariantDefinition) d;
      exps.add(invDef.getExpression());
    }

    AReturnStmCG returnStmCg = new AReturnStmCG();

    if (exps.isEmpty()) {
      // Should not really be necessary
      returnStmCg.setExp(question.getExpAssistant().consBoolLiteral(true));
    } else if (exps.size() == 1) {
      SExpCG expCg = exps.get(0).apply(question.getExpVisitor(), question);
      returnStmCg.setExp(expCg);
    } else {
      // We have more than one expressions from which we will build an 'and chain'
      AAndBoolBinaryExpCG andExpTopCg = new AAndBoolBinaryExpCG();
      andExpTopCg.setType(new ABoolBasicTypeCG());
      andExpTopCg.setLeft(exps.get(0).apply(question.getExpVisitor(), question));

      AAndBoolBinaryExpCG previousAndExpCg = andExpTopCg;

      // The remaining ones except the last
      for (int i = 1; i < exps.size() - 1; i++) {
        SExpCG nextExpCg = exps.get(i).apply(question.getExpVisitor(), question);

        AAndBoolBinaryExpCG nextAndExpCg = new AAndBoolBinaryExpCG();
        nextAndExpCg.setType(new ABoolBasicTypeCG());
        nextAndExpCg.setLeft(nextExpCg);

        previousAndExpCg.setRight(nextAndExpCg);
        previousAndExpCg = nextAndExpCg;
      }

      previousAndExpCg.setRight(
          exps.get(exps.size() - 1).apply(question.getExpVisitor(), question));

      returnStmCg.setExp(andExpTopCg);
    }

    return returnStmCg;
  }
  public SatisfiabilityObligation(
      AClassInvariantDefinition node, IPOContextStack ctxt, IPogAssistantFactory af)
      throws AnalysisException {
    super(node, POType.STATE_INV_SAT, ctxt, node.getLocation(), af);

    AExistsExp exists_exp = new AExistsExp();
    exists_exp.setType(new ABooleanBasicType());
    List<PMultipleBind> binds = stateInvBinds(node);

    exists_exp.setBindList(binds);
    exists_exp.setPredicate(node.getExpression().clone());

    stitch = exists_exp;
    valuetree.setPredicate(ctxt.getPredWithContext(exists_exp));
  }
  protected List<PMultipleBind> stateInvBinds(AClassInvariantDefinition node) {
    List<PMultipleBind> binds = new LinkedList<PMultipleBind>();

    for (PDefinition p : node.getClassDefinition().getDefinitions()) {
      if (p instanceof AInstanceVariableDefinition) {
        binds.add(getMultipleTypeBind(p.getType().clone(), p.getName().clone()));
      }
    }

    return binds;
  }