예제 #1
0
 private Set<PExp> getModuleLevelAssertionsOfType(ClauseType type) {
   Set<PExp> result = new LinkedHashSet<>();
   List<GlobalMathAssertionSymbol> assertions = new LinkedList<>();
   List<FacilitySymbol> facilities = new LinkedList<>();
   try {
     assertions.addAll(
         moduleScope
             .query(
                 new SymbolTypeQuery<GlobalMathAssertionSymbol>(GlobalMathAssertionSymbol.class))
             .stream()
             .filter(e -> e.getClauseType() == type)
             .collect(Collectors.toList()));
     facilities.addAll(
         moduleScope.query(new SymbolTypeQuery<FacilitySymbol>(FacilitySymbol.class)));
   } catch (NoSuchModuleException | UnexpectedSymbolException e) {
   }
   return assertions
       .stream()
       .map(assertion -> substituteByFacilities(facilities, assertion))
       .collect(Collectors.toSet());
 }
예제 #2
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;
  }