Пример #1
0
 @Override
 public void exitCallStmt(ResolveParser.CallStmtContext ctx) {
   VCRuleBackedStat s = null;
   PApply callExp = (PApply) tr.exprASTs.get(ctx.progParamExp());
   OperationSymbol op = getOperation(moduleScope, callExp);
   if (inSimpleForm(op.getEnsures(), op.getParameters())) {
     // TODO: Use log instead!
     // gen.getCompiler().info("APPLYING EXPLICIT (SIMPLE) CALL RULE");
     s = new VCCall(ctx, assertiveBlocks.peek(), EXPLICIT_CALL_APPLICATION, callExp);
   } else {
     // TODO: Use log instead!
     // gen.getCompiler().info("APPLYING GENERAL CALL RULE");
     s = new VCCall(ctx, assertiveBlocks.peek(), GENERAL_CALL_APPLICATION, callExp);
   }
   stats.put(ctx, s);
 }
Пример #2
0
  @Override
  public void enterProcedureDecl(ResolveParser.ProcedureDeclContext ctx) {
    Scope s = symtab.getScope(ctx);
    try {
      List<ProgParameterSymbol> paramSyms = s.getSymbolsOfType(ProgParameterSymbol.class);

      currentProcOpSym =
          s.queryForOne(
              new OperationQuery(
                  null, ctx.name, Utils.apply(paramSyms, ProgParameterSymbol::getDeclaredType)));

      // This is the requires for the operation with some substutions made (see corrFnExp rule in
      // HH-diss)
      PExp corrFnExpRequires =
          perParameterCorrFnExpSubstitute(paramSyms, currentProcOpSym.getRequires());
      List<PExp> opParamAntecedents = new ArrayList<>();
      Utils.apply(paramSyms, opParamAntecedents, this::extractAssumptionsFromParameter);
      Set<PExp> l = getModuleLevelAssertionsOfType(ClauseType.REQUIRES);
      VCAssertiveBlockBuilder block =
          new VCAssertiveBlockBuilder(g, s, "Correct_Op_Hypo=" + ctx.name.getText(), ctx)
              .facilitySpecializations(facilitySpecFormalActualMappings)
              .assume(getModuleLevelAssertionsOfType(ClauseType.REQUIRES))
              // TODO: constraints should be added on demand via NOTICE:...
              // .assume(getModuleLevelAssertionsOfType(ClauseType.CONSTRAINT))
              .assume(opParamAntecedents) // we assume correspondence for reprs here automatically
              .assume(corrFnExpRequires)
              .remember();
      assertiveBlocks.push(block);
    } catch (SymbolTableException e) {
      throw new RuntimeException(e); // this shouldn't happen now
    }
  }
Пример #3
0
  @Override
  public void exitProcedureDecl(ResolveParser.ProcedureDeclContext ctx) {
    Scope scope = symtab.getScope(ctx);
    List<ProgParameterSymbol> paramSyms = scope.getSymbolsOfType(ProgParameterSymbol.class);
    VCAssertiveBlockBuilder block = assertiveBlocks.pop();
    List<ProgParameterSymbol> formalParameters = new ArrayList<>();
    try {
      formalParameters =
          scope.query(new SymbolTypeQuery<ProgParameterSymbol>(ProgParameterSymbol.class));
    } catch (NoSuchModuleException | UnexpectedSymbolException e) {
      e.printStackTrace();
    }

    List<PExp> corrFnExps =
        paramSyms
            .stream()
            .filter(p -> p.getDeclaredType() instanceof PTRepresentation)
            .map(p -> (PTRepresentation) p.getDeclaredType())
            .map(p -> p.getReprTypeSymbol().getCorrespondence())
            .collect(Collectors.toList());
    PExp corrFnExpEnsures =
        perParameterCorrFnExpSubstitute(paramSyms, currentProcOpSym.getEnsures())
            .withVCInfo(ctx.getStart(), "Ensures clause of " + ctx.name.getText());
    // postcondition[params 1..i <-- corr_fn_exp]

    List<PExp> paramConsequents = new ArrayList<>();
    Utils.apply(formalParameters, paramConsequents, this::extractConsequentsFromParameter);

    block
        .stats(Utils.collect(VCRuleBackedStat.class, ctx.stmt(), stats))
        .assume(corrFnExps)
        .confirm(ctx, g.formConjuncts(paramConsequents))
        .finalConfirm(corrFnExpEnsures);

    outputFile.addAssertiveBlock(block.build());
    currentProcOpSym = null;
  }