@Override public void caseACasesExp(ACasesExp node) throws AnalysisException { if (!proceed(node)) { return; } handleCaseNode(node.getExpression(), node.getCases(), node.getOthers()); }
public CasesExhaustiveObligation(ACasesExp exp, IPOContextStack ctxt, IPogAssistantFactory assistantFactory) throws AnalysisException { super(exp, POType.CASES_EXHAUSTIVE, ctxt, exp.getLocation(), assistantFactory); PExp initialExp = alt2Exp(exp.getCases().getFirst(), exp, assistantFactory); List<ACaseAlternative> initialCases = new LinkedList<ACaseAlternative>(exp.getCases()); initialCases.remove(0); PExp pred = recOnExp(exp.clone(), initialCases, initialExp, assistantFactory); stitch = pred.clone(); valuetree.setPredicate(ctxt.getPredWithContext(pred)); }
public static ACasesExp newACasesExp(ILexLocation start, PExp exp, List<ACaseAlternative> cases, PExp others) { ACasesExp result = new ACasesExp(); initExpression(result, start); result.setExpression(exp); result.setCases(cases); result.setOthers(others); return result; }
inACasesExp(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) node.getType().apply(this); if(node.getExpression() != null && !_visitedNodes.contains(node.getExpression())) node.getExpression().apply(this); List<ACaseAlternative> copy = new ArrayList<ACaseAlternative>(node.getCases()); for( ACaseAlternative e : copy) if(node.getOthers() != null && !_visitedNodes.contains(node.getOthers())) node.getOthers().apply(this);
@Override public PType caseACasesExp(ACasesExp node, TypeCheckInfo question) throws AnalysisException { TypeCheckInfo noConstraint = question.newConstraint(null); question.qualifiers = null; PType expType = node.getExpression().apply(THIS, noConstraint); PTypeSet rtypes = new PTypeSet(question.assistantFactory); for (ACaseAlternative c : node.getCases()) { rtypes.add(typeCheck(c, THIS, question, expType)); } if (node.getOthers() != null) { rtypes.add(node.getOthers().apply(THIS, question)); } node.setType(rtypes.getType(node.getLocation())); return node.getType(); }
@Override public Value caseACasesExp(ACasesExp node, Context ctxt) throws AnalysisException { BreakpointManager.getBreakpoint(node).check(node.getLocation(), ctxt); Value val = node.getExpression().apply(VdmRuntime.getExpressionEvaluator(), ctxt); for (ACaseAlternative c : node.getCases()) { Value rv = eval(c, val, ctxt); if (rv != null) { return rv; } } if (node.getOthers() != null) { return node.getOthers().apply(VdmRuntime.getExpressionEvaluator(), ctxt); } return VdmRuntimeError.abort(node.getLocation(), 4004, "No cases apply for " + val, ctxt); }
@Override public LexNameSet caseACasesExp(ACasesExp node, FreeVarInfo info) throws AnalysisException { return node.getExpression().apply(this, info); }
inACasesExp(node, question); if(node.getType() != null && !_visitedNodes.contains(node.getType())) node.getType().apply(this, question); if(node.getExpression() != null && !_visitedNodes.contains(node.getExpression())) node.getExpression().apply(this, question); List<ACaseAlternative> copy = new ArrayList<ACaseAlternative>(node.getCases()); for( ACaseAlternative e : copy) if(node.getOthers() != null && !_visitedNodes.contains(node.getOthers())) node.getOthers().apply(this, question);
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; } }
/** * Creates a deep clone of this {@link ACasesExp} node while putting all * old node-new node relations in the map {@code oldToNewMap}. * @param oldToNewMap the map filled with the old node-new node relation * @return a deep clone of this {@link ACasesExp} node */ public ACasesExp clone(Map<INode,INode> oldToNewMap) { ACasesExp node = new ACasesExp( _type, _location, cloneNode(_expression, oldToNewMap), cloneList(_cases, oldToNewMap), cloneNode(_others, oldToNewMap) ); oldToNewMap.put(this, node); return node; }
inACasesExp(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) node.getType().apply(this); if(node.getExpression() != null && !_visitedNodes.contains(node.getExpression())) node.getExpression().apply(this); List<ACaseAlternative> copy = new ArrayList<ACaseAlternative>(node.getCases()); for( ACaseAlternative e : copy) if(node.getOthers() != null && !_visitedNodes.contains(node.getOthers())) node.getOthers().apply(this);
@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; }
mergeReturns(retVal,inACasesExp(node, question)); if(node.getType() != null && !_visitedNodes.contains(node.getType())) mergeReturns(retVal,node.getType().apply(this, question)); if(node.getExpression() != null && !_visitedNodes.contains(node.getExpression())) mergeReturns(retVal,node.getExpression().apply(this, question)); List<ACaseAlternative> copy = new ArrayList<ACaseAlternative>(node.getCases()); for( ACaseAlternative e : copy) if(node.getOthers() != null && !_visitedNodes.contains(node.getOthers())) mergeReturns(retVal,node.getOthers().apply(this, question));
@Override public ValueList caseACasesExp(ACasesExp exp, ObjectContext ctxt) throws AnalysisException { ValueList list = exp.getExpression().apply(THIS, ctxt); for (ACaseAlternative c : exp.getCases()) { list.addAll(c.apply(THIS, ctxt)); } if (exp.getOthers() != null) { list.addAll(exp.getOthers().apply(THIS, ctxt)); } return list; }
mergeReturns(retVal,inACasesExp(node)); if(node.getType() != null && !_visitedNodes.contains(node.getType())) mergeReturns(retVal,node.getType().apply(this)); if(node.getExpression() != null && !_visitedNodes.contains(node.getExpression())) mergeReturns(retVal,node.getExpression().apply(this)); List<ACaseAlternative> copy = new ArrayList<ACaseAlternative>(node.getCases()); for( ACaseAlternative e : copy) if(node.getOthers() != null && !_visitedNodes.contains(node.getOthers())) mergeReturns(retVal,node.getOthers().apply(this));
public LexNameList caseACasesExp(ACasesExp expression) throws org.overture.ast.analysis.AnalysisException { LexNameList list = af.createPExpAssistant().getOldNames(expression.getExpression()); for (ACaseAlternative c : expression.getCases()) { list.addAll(c.apply(this)); } if (expression.getOthers() != null) { list.addAll(af.createPExpAssistant().getOldNames(expression.getOthers())); } return list; }
@Override public SExpIR caseACasesExp(ACasesExp node, IRInfo question) throws AnalysisException { PType type = node.getType(); PExp exp = node.getExpression(); PExp others = node.getOthers(); LinkedList<ACaseAlternative> cases = node.getCases(); STypeIR typeCg = type.apply(question.getTypeVisitor(), question); SExpIR expCg = exp.apply(question.getExpVisitor(), question); SExpIR othersCg = others != null ? others.apply(question.getExpVisitor(), question) : null; ACasesExpIR casesExpCg = new ACasesExpIR(); casesExpCg.setType(typeCg); casesExpCg.setExp(expCg); casesExpCg.setOthers(othersCg); question.getExpAssistant().handleAlternativesCasesExp(question, exp, cases, casesExpCg.getCases()); return casesExpCg; }
@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; }
for (ACaseAlternative alt : node.getCases()) PType type = node.getExpression().getType(); if (node.getOthers() != null) obligations.addAll(node.getOthers().apply(mainVisitor, question)); if (node.getOthers() == null && !hasIgnore)