inACaseAlternative(node); if(node.getCexp() != null && !_visitedNodes.contains(node.getCexp())) node.getCexp().apply(this); if(node.getPattern() != null && !_visitedNodes.contains(node.getPattern())) node.getPattern().apply(this); if(node.getResult() != null && !_visitedNodes.contains(node.getResult())) node.getResult().apply(this); List<PDefinition> copy = new ArrayList<PDefinition>(node.getDefs()); for( PDefinition e : copy) if(node.getType() != null && !_visitedNodes.contains(node.getType())) node.getType().apply(this); if(node.getExpType() != null && !_visitedNodes.contains(node.getExpType())) node.getExpType().apply(this);
if (c.getDefs().size() == 0) 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) c.getDefs().clear(); throw 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()); Environment local = new FlatCheckedEnvironment(question.assistantFactory, c.getDefs(), question.env, question.scope); question = question.newInfo(local); c.setType(c.getResult().apply(rootVisitor, question)); local.unusedCheck();
/** * Creates a new complete constructor {@code ACaseAlternative} node with the given nodes as children. * @deprecated This method should not be used, use AstFactory instead. * The basic child nodes are removed from their previous parents. * @param location_ the {@link ILexLocation} node for the {@code location} child of this {@link ACaseAlternative} node * @param cexp_ the {@link PExp} node for the {@code cexp} child of this {@link ACaseAlternative} node * @param pattern_ the {@link PPattern} node for the {@code pattern} child of this {@link ACaseAlternative} node * @param result_ the {@link PExp} node for the {@code result} child of this {@link ACaseAlternative} node * @param defs_ the {@link NodeList} node for the {@code defs} child of this {@link ACaseAlternative} node * @param type_ the {@link PType} <b>graph</a> node for the {@code type} child of this {@link ACaseAlternative} node. * <i>The parent of this {@code type } will not be changed by adding it to this node.</i> * @param expType_ the {@link PType} <b>graph</a> node for the {@code expType} child of this {@link ACaseAlternative} node. * <i>The parent of this {@code expType } will not be changed by adding it to this node.</i> */ public ACaseAlternative(ILexLocation location_, PExp cexp_, PPattern pattern_, PExp result_, List<? extends PDefinition> defs_, PType type_, PType expType_) { super(); this.setLocation(location_); this.setCexp(cexp_); this.setPattern(pattern_); this.setResult(result_); this.setDefs(defs_); this.setType(type_); this.setExpType(expType_); }
@Override public void caseACaseAlternative(ACaseAlternative node) throws AnalysisException { if (!proceed(node)) { return; } handleCase(node.getDefs(), node.getPattern(), node.getResult()); }
@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()); } }
if (alt.getPattern() instanceof AIgnorePattern) PPattern pattern = alt.getPattern(); PExp cexp = alt.getCexp(); PType type = node.getExpression().getType(); obligations.addAll(alt.getResult().apply(rootVisitor, question)); question.pop(); question.push(new PONotCaseContext(pattern, type, cexp.clone(), aF));
/** * 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; }
@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; }
@Override public List<PExp> caseACasesExp(ACasesExp exp) throws AnalysisException { List<PExp> subs = exp.getExpression().apply(THIS); for (ACaseAlternative c : exp.getCases()) { subs.addAll(c.apply(THIS)); } if (exp.getOthers() != null) { subs.addAll(exp.getOthers().apply(THIS)); } subs.add(exp); return subs; }
SExpIR altCg = alt.apply(question.getExpVisitor(), question); casesCg.add((ACaseAltExpExpIR) altCg); 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);
@Override public List<PExp> caseACaseAlternative(ACaseAlternative exp) throws AnalysisException { return exp.getResult().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; } }
e.apply(this);
/** * This is not an expression */ @Override public LexNameList caseACaseAlternative(ACaseAlternative c) throws AnalysisException { return af.createPExpAssistant().getOldNames(c.getResult()); }
inACaseAlternative(node, question); if(node.getCexp() != null && !_visitedNodes.contains(node.getCexp())) node.getCexp().apply(this, question); if(node.getPattern() != null && !_visitedNodes.contains(node.getPattern())) node.getPattern().apply(this, question); if(node.getResult() != null && !_visitedNodes.contains(node.getResult())) node.getResult().apply(this, question); List<PDefinition> copy = new ArrayList<PDefinition>(node.getDefs()); for( PDefinition e : copy) if(node.getType() != null && !_visitedNodes.contains(node.getType())) node.getType().apply(this, question); if(node.getExpType() != null && !_visitedNodes.contains(node.getExpType())) node.getExpType().apply(this, question);
e.apply(this, question);
@Override public PExp caseACasesExp(ACasesExp exp, Integer lineno) throws AnalysisException { PExp found = findExpressionBaseCase(exp, lineno); if (found != null) { return found; } found = exp.getExpression().apply(THIS, lineno);// PExpAssistantInterpreter.findExpression(exp.getExpression(), // lineno); if (found != null) { return found; } for (ACaseAlternative c : exp.getCases()) { found = c.getResult().apply(THIS, lineno);// PExpAssistantInterpreter.findExpression(c.getResult(), lineno); if (found != null) { break; } } return found != null ? found : exp.getOthers() != null ? exp.getOthers().apply(THIS, lineno)// PExpAssistantInterpreter.findExpression(exp.getOthers(), // lineno) : null; }
inACaseAlternative(node); if(node.getCexp() != null && !_visitedNodes.contains(node.getCexp())) node.getCexp().apply(this); if(node.getPattern() != null && !_visitedNodes.contains(node.getPattern())) node.getPattern().apply(this); if(node.getResult() != null && !_visitedNodes.contains(node.getResult())) node.getResult().apply(this); List<PDefinition> copy = new ArrayList<PDefinition>(node.getDefs()); for( PDefinition e : copy) if(node.getType() != null && !_visitedNodes.contains(node.getType())) node.getType().apply(this); if(node.getExpType() != null && !_visitedNodes.contains(node.getExpType())) node.getExpType().apply(this);
e.apply(this);
mergeReturns(retVal,inACaseAlternative(node)); if(node.getCexp() != null && !_visitedNodes.contains(node.getCexp())) mergeReturns(retVal,node.getCexp().apply(this)); if(node.getPattern() != null && !_visitedNodes.contains(node.getPattern())) mergeReturns(retVal,node.getPattern().apply(this)); if(node.getResult() != null && !_visitedNodes.contains(node.getResult())) mergeReturns(retVal,node.getResult().apply(this)); List<PDefinition> copy = new ArrayList<PDefinition>(node.getDefs()); for( PDefinition e : copy) if(node.getType() != null && !_visitedNodes.contains(node.getType())) mergeReturns(retVal,node.getType().apply(this)); if(node.getExpType() != null && !_visitedNodes.contains(node.getExpType())) mergeReturns(retVal,node.getExpType().apply(this));