private List<PExp> extractConsequentsFromParameter(ProgParameterSymbol p) {
    List<PExp> result = new ArrayList<>();
    PExp incParamExp = new PSymbolBuilder(p.asPSymbol()).incoming(true).build();
    PExp paramExp = new PSymbolBuilder(p.asPSymbol()).incoming(false).build();

    if (p.getDeclaredType() instanceof ProgNamedType) {
      ProgNamedType t = (ProgNamedType) p.getDeclaredType();
      PExp exemplar = new PSymbolBuilder(t.getExemplarName()).mathClssfctn(t.toMath()).build();

      if (t instanceof PTRepresentation) {
        ProgReprTypeSymbol repr = ((PTRepresentation) t).getReprTypeSymbol();

        PExp convention = repr.getConvention();
        PExp corrFnExp = repr.getCorrespondence();
        result.add(convention.substitute(t.getExemplarAsPSymbol(), paramExp));
      }
      if (p.getMode() == ParameterMode.PRESERVES || p.getMode() == ParameterMode.RESTORES) {
        PExp equalsExp =
            g.formEquals(paramExp, incParamExp)
                .withVCInfo(
                    p.getDefiningTree().getStart(),
                    "Ensure parameter " + p.getName() + " is restored");
        result.add(equalsExp);
      } else if (p.getMode() == ParameterMode.CLEARS) {
        PExp init =
            ((ProgNamedType) p.getDeclaredType())
                .getInitializationEnsures()
                .substitute(exemplar, paramExp);
        result.add(init);
      }
    }
    return result;
  }
  private List<PExp> extractAssumptionsFromParameter(ProgParameterSymbol p) {
    List<PExp> resultingAssumptions = new ArrayList<>();
    if (p.getDeclaredType() instanceof ProgNamedType) {

      // both PTFamily AND PTRepresentation are a PTNamed
      ProgNamedType declaredType = (ProgNamedType) p.getDeclaredType();
      PExp exemplar = declaredType.getExemplarAsPSymbol();
      if (declaredType instanceof ProgFamilyType) {
        PExp constraint = ((ProgFamilyType) declaredType).getConstraint();

        constraint = constraint.substitute(getSpecializationsForFacility(p.getTypeQualifier()));
        resultingAssumptions.add(
            constraint.substitute(
                declaredType.getExemplarAsPSymbol(),
                p.asPSymbol())); // ASSUME TC (type constraint -- since we're conceptual)
      } else if (declaredType instanceof PTRepresentation) {
        ProgReprTypeSymbol repr = ((PTRepresentation) declaredType).getReprTypeSymbol();
        PExp convention = repr.getConvention();

        resultingAssumptions.add(
            convention.substitute(declaredType.getExemplarAsPSymbol(), p.asPSymbol()));
        // ASSUME RC (repr convention -- since we're a repr)
        resultingAssumptions.add(repr.getCorrespondence());
      }
    } else { // PTGeneric
      //    resultingAssumptions.add(g.formInitializationPredicate(
      //            p.getDeclaredType(), p.getName()));
    }
    return resultingAssumptions;
  }
  @Override
  public void enterTypeImplInit(ResolveParser.TypeImplInitContext ctx) {
    Scope s = symtab.getScope(ctx.getParent());
    PExp convention = currentTypeReprSym.getConvention();
    PExp correspondence = currentTypeReprSym.getCorrespondence();
    PExp typeInitEnsures = g.getTrueExp();
    List<ModuleParameterSymbol> moduleParamSyms = getAllModuleParameterSyms();

    VCAssertiveBlockBuilder block =
        new VCAssertiveBlockBuilder(g, s, "T_Init_Hypo=" + currentTypeReprSym.getName(), ctx)
            .assume(getModuleLevelAssertionsOfType(ClauseType.REQUIRES))
            .assume(
                getAssertionsFromModuleFormalParameters(
                    moduleParamSyms, this::extractAssumptionsFromParameter));

    assertiveBlocks.push(block);
  }
 @Override
 public void exitTypeImplInit(ResolveParser.TypeImplInitContext ctx) {
   PExp typeInitEnsures = g.getTrueExp();
   PExp convention = currentTypeReprSym.getConvention();
   PExp correspondence = currentTypeReprSym.getCorrespondence();
   if (currentTypeReprSym.getDefinition() != null) {
     typeInitEnsures =
         currentTypeReprSym.getDefinition().getProgramType().getInitializationEnsures();
   }
   VCAssertiveBlockBuilder block = assertiveBlocks.pop();
   PExp newInitEnsures =
       typeInitEnsures.substitute(
           currentTypeReprSym.exemplarAsPSymbol(),
           currentTypeReprSym.conceptualExemplarAsPSymbol());
   // block.stats(Utils.collect(VCRuleBackedStat.class, ctx.stmt(), stats));
   // block.confirm(convention);  //order here is important
   block.assume(correspondence);
   throw new UnsupportedOperationException("re-institute the final confirm for this dan");
   // block.finalConfirm(newInitEnsures, "Initialization-ensures clause of " +
   // currentTypeReprSym.getName());
   // outputFile.addAssertiveBlock(block.build());
 }
  @Override
  public void enterTypeRepresentationDecl(ResolveParser.TypeRepresentationDeclContext ctx) {
    Scope s = symtab.getScope(ctx);
    currentTypeReprSym = null;
    try {
      currentTypeReprSym =
          moduleScope
              .queryForOne(new UnqualifiedNameQuery(ctx.name.getText()))
              .toProgReprTypeSymbol();
    } catch (SymbolTableException e) {
    }
    List<PExp> opParamAntecedents =
        getAssertionsFromModuleFormalParameters(
            getAllModuleParameterSyms(), this::extractAssumptionsFromParameter);

    VCAssertiveBlockBuilder block =
        new VCAssertiveBlockBuilder(g, s, "Well_Def_Corr_Hyp=" + ctx.name.getText(), ctx)
            .assume(opParamAntecedents)
            .assume(getModuleLevelAssertionsOfType(ClauseType.REQUIRES))
            .assume(currentTypeReprSym.getConvention());
    assertiveBlocks.push(block);
  }
  private void confirmParameterConsequentsForBlock(
      VCAssertiveBlockBuilder block, ProgParameterSymbol p) {
    PExp incParamExp = new PSymbolBuilder(p.asPSymbol()).incoming(true).build();
    PExp paramExp = new PSymbolBuilder(p.asPSymbol()).incoming(false).build();

    if (p.getDeclaredType() instanceof ProgNamedType) {
      ProgNamedType t = (ProgNamedType) p.getDeclaredType();
      PExp exemplar = new PSymbolBuilder(t.getExemplarName()).mathClssfctn(t.toMath()).build();

      if (t instanceof PTRepresentation) {
        ProgReprTypeSymbol repr = ((PTRepresentation) t).getReprTypeSymbol();

        PExp convention = repr.getConvention();
        PExp corrFnExp = repr.getCorrespondence();
        // if we're doing this its going to be on a procedure decl or op-proc decl, so just
        // say block.definingTree
        PExp newConvention =
            convention
                .substitute(t.getExemplarAsPSymbol(), paramExp)
                .withVCInfo(block.definingTree.getStart(), "Convention for " + t.getName());
        block.confirm(block.definingTree, newConvention);
      }
      if (p.getMode() == ParameterMode.PRESERVES || p.getMode() == ParameterMode.RESTORES) {
        PExp equalsExp =
            g.formEquals(paramExp, incParamExp)
                .withVCInfo(
                    block.definingTree.getStart(),
                    "Ensure parameter " + p.getName() + " is restored");
        block.confirm(block.definingTree, equalsExp);
      } else if (p.getMode() == ParameterMode.CLEARS) {
        PExp init =
            ((ProgNamedType) p.getDeclaredType())
                .getInitializationEnsures()
                .substitute(exemplar, paramExp);
        // result.add(init);
      }
    }
  }