public static String getCasesString(ACasesStm stm) { StringBuilder sb = new StringBuilder(); sb.append("cases " + stm.getExp() + " :\n"); for (ACaseAlternativeStm csa : stm.getCases()) { sb.append(" "); sb.append(csa.toString()); } if (stm.getOthers() != null) { sb.append(" others -> "); sb.append(stm.getOthers().toString()); } sb.append(" end"); return sb.toString(); }
@Override public void caseACasesStm(ACasesStm node) throws AnalysisException { if (!proceed(node)) { return; } handleCaseNode(node.getExp(), node.getCases(), node.getOthers()); }
@Override public IProofObligationList caseACasesStm(ACasesStm node, IPOContextStack question) throws AnalysisException { try { IProofObligationList obligations = new ProofObligationList(); boolean hasIgnore = false; for (ACaseAlternativeStm alt : node.getCases()) { if (alt.getPattern() instanceof AIgnorePattern) { hasIgnore = true; } obligations.addAll(alt.apply(mainVisitor, question)); } if (node.getOthers() != null && !hasIgnore) { obligations.addAll(node.getOthers().apply(rootVisitor, question)); } return obligations; } catch (Exception e) { throw new POException(node, e.getMessage()); } }
@Override public Value caseACasesStm(ACasesStm node, Context ctxt) throws AnalysisException { BreakpointManager.getBreakpoint(node).check(node.getLocation(), ctxt); Value val = node.getExp().apply(VdmRuntime.getStatementEvaluator(), ctxt); for (ACaseAlternativeStm c : node.getCases()) { Value rv = eval(c, val, ctxt); if (rv != null) { return rv; } } if (node.getOthers() != null) { return node.getOthers().apply(VdmRuntime.getStatementEvaluator(), ctxt); } return new VoidValue(); }
@Override public PType caseACasesStm(ACasesStm node, TypeCheckInfo question) throws AnalysisException { PType expType = node.getExp().apply(THIS, question); PTypeSet rtypes = new PTypeSet(question.assistantFactory); boolean always = false; for (ACaseAlternativeStm c : node.getCases()) { c.setCtype(expType); rtypes.add(c.apply(THIS, question)); always = always || question.assistantFactory.createPPatternAssistant().alwaysMatches(c.getPattern(), expType); } if (node.getOthers() != null) { rtypes.add(node.getOthers().apply(THIS, question)); } else if (!always) { rtypes.add(AstFactory.newAVoidType(node.getLocation())); } node.setType(rtypes.getType(node.getLocation())); return node.getType(); }
@Override public SStmIR caseACasesStm(ACasesStm node, IRInfo question) throws AnalysisException { PExp exp = node.getExp(); PStm others = node.getOthers(); LinkedList<ACaseAlternativeStm> cases = node.getCases(); SExpIR expCg = exp.apply(question.getExpVisitor(), question); SStmIR othersCg = others != null ? others.apply(question.getStmVisitor(), question) : null; ACasesStmIR casesStmCg = new ACasesStmIR(); casesStmCg.setExp(expCg); casesStmCg.setOthers(othersCg); question.getStmAssistant().handleAlternativesCasesStm(question, exp, cases, casesStmCg.getCases()); return casesStmCg; }