@Override public void caseACaseAlternative(ACaseAlternative node) throws AnalysisException { if (!proceed(node)) { return; } handleCase(node.getDefs(), node.getPattern(), node.getResult()); }
question.assistantFactory.createPPatternAssistant().typeResolve(c.getPattern(), rootVisitor, new TypeCheckInfo(question.assistantFactory, question.env)); if (c.getPattern() instanceof AExpressionPattern) AExpressionPattern ep = (AExpressionPattern) c.getPattern(); PType ptype = ep.getExp().apply(rootVisitor, new TypeCheckInfo(question.assistantFactory, question.env, question.scope)); TypeCheckerErrors.report(3311, "Pattern cannot match", c.getPattern().getLocation(), c.getPattern()); question.assistantFactory.createPPatternAssistant().typeResolve(c.getPattern(), rootVisitor, new TypeCheckInfo(question.assistantFactory, question.env)); c.getDefs().addAll(question.assistantFactory.createPPatternAssistant().getDefinitions(c.getPattern(), expType, NameScope.LOCAL)); } catch (TypeCheckException e) question.assistantFactory.createPPatternAssistant().typeCheck(c.getPattern(), question, rootVisitor); question.assistantFactory.createPDefinitionListAssistant().typeCheck(c.getDefs(), rootVisitor, new TypeCheckInfo(question.assistantFactory, question.env, question.scope)); if (!question.assistantFactory.createPPatternAssistant().matches(c.getPattern(), expType)) TypeCheckerErrors.report(3311, "Pattern cannot match", c.getPattern().getLocation(), c.getPattern());
if(node.getPattern() != null && !_visitedNodes.contains(node.getPattern())) node.getPattern().apply(this);
private PExp alt2Exp(ACaseAlternative alt, ACasesExp exp, IPogAssistantFactory assistantFactory) throws AnalysisException { if (assistantFactory.createPPatternAssistant().isSimple(alt.getPattern())) { AEqualsBinaryExp equalsExp = AstExpressionFactory.newAEqualsBinaryExp(exp.getExpression().clone(), patternToExp(alt.getPattern().clone())); return equalsExp; } else { PExp matching = patternToExp(alt.getPattern().clone()); AExistsExp existsExp = new AExistsExp(); ATypeMultipleBind tbind = new ATypeMultipleBind(); List<PPattern> plist = new LinkedList<PPattern>(); plist.add(alt.getPattern().clone()); tbind.setPlist(plist); tbind.setType(exp.getExpression().getType().clone()); List<PMultipleBind> bindList = new LinkedList<PMultipleBind>(); bindList.add(tbind); existsExp.setBindList(bindList); AEqualsBinaryExp equalsExp = AstExpressionFactory.newAEqualsBinaryExp(exp.getExpression().clone(), matching); existsExp.setPredicate(equalsExp); return existsExp; } }
if(node.getPattern() != null && !_visitedNodes.contains(node.getPattern())) node.getPattern().apply(this);
if(node.getPattern() != null && !_visitedNodes.contains(node.getPattern())) node.getPattern().apply(this, question);
@Override public IProofObligationList caseACaseAlternative(ACaseAlternative node, IPOContextStack question) throws AnalysisException { try { IProofObligationList obligations = new ProofObligationList(); question.push(new POCaseContext(node.getPattern(), node.getType(), node.getCexp(), assistantFactory)); obligations.addAll(node.getResult().apply(this.pogExpVisitor, question)); question.pop(); question.push(new PONotCaseContext(node.getPattern(), node.getType(), node.getCexp(), assistantFactory)); return obligations; } catch (Exception e) { throw new POException(node, e.getMessage()); } }
@Override public SExpIR caseACaseAlternative(ACaseAlternative node, IRInfo question) throws AnalysisException { PPattern pattern = node.getPattern(); PExp result = node.getResult(); SPatternIR patternCg = pattern.apply(question.getPatternVisitor(), question); SExpIR resultCg = result.apply(question.getExpVisitor(), question); ACaseAltExpExpIR altCg = new ACaseAltExpExpIR(); altCg.setPattern(patternCg); altCg.setResult(resultCg); return altCg; }
if(node.getPattern() != null && !_visitedNodes.contains(node.getPattern())) mergeReturns(retVal,node.getPattern().apply(this));
if(node.getPattern() != null && !_visitedNodes.contains(node.getPattern())) mergeReturns(retVal,node.getPattern().apply(this, question));
ACaseAltExpExpIR cgCase = casesCg.get(i); PType patternType = question.getAssistantManager().getTypeAssistant().getType(question, unionType, vdmCase.getPattern()); STypeIR patternTypeCg = patternType.apply(question.getTypeVisitor(), question); cgCase.setPatternType(patternTypeCg);
/** * Utility method for ACaseAlternative * * @param node * @param val * @param ctxt * @return * @throws AnalysisException */ public Value eval(ACaseAlternative node, Value val, Context ctxt) throws AnalysisException { Context evalContext = new Context(ctxt.assistantFactory, node.getLocation(), "case alternative", ctxt); try { evalContext.putList(ctxt.assistantFactory.createPPatternAssistant().getNamedValues(node.getPattern(), val, ctxt)); return node.getResult().apply(VdmRuntime.getExpressionEvaluator(), evalContext); } catch (PatternMatchException e) { // Silently fail (CasesExpression will try the others) } return null; }
if (alt.getPattern() instanceof AIgnorePattern) PPattern pattern = alt.getPattern(); PExp cexp = alt.getCexp(); PType type = node.getExpression().getType();