コード例 #1
0
  @Override
  public List<PDefinition> caseAImplicitFunctionDefinition(AImplicitFunctionDefinition node)
      throws AnalysisException {
    List<PDefinition> defs = new Vector<PDefinition>();
    defs.add(node);

    if (node.getPredef() != null) {
      defs.add(node.getPredef());
    }

    if (node.getPostdef() != null) {
      defs.add(node.getPostdef());
    }

    return defs;
  }
コード例 #2
0
  public SatisfiabilityObligation(
      AImplicitFunctionDefinition func, IPOContextStack ctxt, IPogAssistantFactory af)
      throws AnalysisException {
    super(func, POType.FUNC_SATISFIABILITY, ctxt, func.getLocation(), af);

    /** f: A * B -> R [pre ...] post ... [pre_f(a, b) =>] exists r:R & post_f(a, b, r) */
    List<PExp> arglist = new Vector<PExp>();

    for (APatternListTypePair pltp : func.getParamPatterns()) {
      for (PPattern pattern : pltp.getPatterns()) {
        arglist.add(patternToExp(pattern));
      }
    }

    AApplyExp preApply = null;

    if (func.getPredef() != null) {
      preApply =
          getApplyExp(
              getVarExp(func.getPredef().getName().clone(), func.getPredef().clone()), arglist);
      preApply.setType(new ABooleanBasicType());
      preApply.getRoot().setType(func.getPredef().getType().clone());
    }

    AExistsExp existsExp = new AExistsExp();
    existsExp.setType(new ABooleanBasicType());
    List<PExp> postArglist = new Vector<PExp>(arglist);

    if (func.getResult().getPattern() instanceof AIdentifierPattern) {
      AIdentifierPattern ip = (AIdentifierPattern) func.getResult().getPattern().clone();
      postArglist.add(patternToExp(func.getResult().getPattern()));
      existsExp.setBindList(
          getMultipleTypeBindList(func.getResult().getType().clone(), ip.getName()));
    } else {
      throw new RuntimeException("Expecting identifier pattern in function result");
    }

    AApplyExp postApply =
        getApplyExp(getVarExp(func.getPostdef().getName(), func.getPostdef()), postArglist);
    postApply.setType(new ABooleanBasicType());
    postApply.getRoot().setType(func.getPostdef().getType().clone());
    existsExp.setPredicate(postApply);

    if (preApply != null) {
      AImpliesBooleanBinaryExp implies =
          AstExpressionFactory.newAImpliesBooleanBinaryExp(preApply, existsExp);
      stitch = implies;
      valuetree.setPredicate(ctxt.getPredWithContext(implies));
    } else {
      stitch = existsExp;
      valuetree.setPredicate(ctxt.getPredWithContext(existsExp));
    }

    // valuetree.setContext(ctxt.getContextNodeList());
  }