inACaseAlternativeStm(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.getCtype() != null && !_visitedNodes.contains(node.getCtype())) node.getCtype().apply(this, question);
private Value eval(ACaseAlternativeStm node, Value val, Context ctxt) throws AnalysisException { Context evalContext = new Context(ctxt.assistantFactory, node.getLocation(), "case alternative", ctxt); node.getPattern().getLocation().hit(); node.getLocation().hit(); try { evalContext.putList(ctxt.assistantFactory.createPPatternAssistant().getNamedValues(node.getPattern(), val, ctxt)); return node.getResult().apply(VdmRuntime.getStatementEvaluator(), evalContext); } catch (PatternMatchException e) { // CasesStatement tries the others } return null; }
/** * Creates a new complete constructor {@code ACaseAlternativeStm} 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 ACaseAlternativeStm} node * @param cexp_ the {@link PExp} node for the {@code cexp} child of this {@link ACaseAlternativeStm} node * @param pattern_ the {@link PPattern} node for the {@code pattern} child of this {@link ACaseAlternativeStm} node * @param result_ the {@link PStm} node for the {@code result} child of this {@link ACaseAlternativeStm} node * @param defs_ the {@link GraphNodeList} <b>graph</a> node for the {@code defs} child of this {@link ACaseAlternativeStm} node. * <i>The parent of this {@code defs } will not be changed by adding it to this node.</i> * @param ctype_ the {@link PType} <b>graph</a> node for the {@code ctype} child of this {@link ACaseAlternativeStm} node. * <i>The parent of this {@code ctype } will not be changed by adding it to this node.</i> */ public ACaseAlternativeStm(ILexLocation location_, PExp cexp_, PPattern pattern_, PStm result_, List<? extends PDefinition> defs_, PType ctype_) { super(); this.setLocation(location_); this.setCexp(cexp_); this.setPattern(pattern_); this.setResult(result_); this.setDefs(defs_); this.setCtype(ctype_); }
public static ACaseAlternativeStm newACaseAlternativeStm(PPattern pattern, PStm stmt) { ACaseAlternativeStm result = new ACaseAlternativeStm(); result.setLocation(pattern.getLocation()); result.getLocation().executable(true); result.setPattern(pattern); result.setResult(stmt); return result; }
@Override public void caseACaseAlternativeStm(ACaseAlternativeStm node) throws AnalysisException { if (!proceed(node)) { return; } handleCase(node.getDefs(), node.getPattern(), node.getResult()); }
if (node.getDefs().size() == 0) node.setDefs(new LinkedList<PDefinition>()); question.assistantFactory.createPPatternAssistant().typeResolve(node.getPattern(), THIS, question); if (node.getPattern() instanceof AExpressionPattern) AExpressionPattern ep = (AExpressionPattern) node.getPattern(); PType ptype = ep.getExp().apply(THIS, question); if (!question.assistantFactory.getTypeComparator().compatible(ptype, node.getCtype())) TypeCheckerErrors.report(3311, "Pattern cannot match", node.getPattern().getLocation(), node.getPattern()); question.assistantFactory.createPPatternAssistant().typeResolve(node.getPattern(), THIS, question); ACasesStm stm = (ACasesStm) node.parent(); node.getDefs().addAll(question.assistantFactory.createPPatternAssistant().getDefinitions(node.getPattern(), stm.getExp().getType(), NameScope.LOCAL)); question.assistantFactory.createPDefinitionListAssistant().typeCheck(node.getDefs(), THIS, question); if (!question.assistantFactory.createPPatternAssistant().matches(node.getPattern(), node.getCtype())) TypeCheckerErrors.report(3311, "Pattern cannot match", node.getPattern().getLocation(), node.getPattern()); Environment local = new FlatCheckedEnvironment(question.assistantFactory, node.getDefs(), question.env, question.scope); PType r = node.getResult().apply(THIS, new TypeCheckInfo(question.assistantFactory, local, question.scope, null, null, question.returnType)); local.unusedCheck();
@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 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 caseACaseAlternativeStm(ACaseAlternativeStm node, IRInfo question) throws AnalysisException { PPattern pattern = node.getPattern(); PStm result = node.getResult(); SPatternIR patternCg = pattern.apply(question.getPatternVisitor(), question); SStmIR resultCg = result.apply(question.getStmVisitor(), question); ACaseAltStmStmIR caseCg = new ACaseAltStmStmIR(); caseCg.setPattern(patternCg); caseCg.setResult(resultCg); return caseCg; }
@Override public PTypeSet caseACaseAlternativeStm(ACaseAlternativeStm statement) throws AnalysisException { return statement.getResult().apply(THIS); }
@Override public PTypeSet caseACasesStm(ACasesStm statement) throws AnalysisException { PTypeSet types = new PTypeSet(af); for (ACaseAlternativeStm c : statement.getCases()) { types.addAll(c.apply(THIS)); } return types; }
SStmIR altCg = alt.apply(question.getStmVisitor(), question); casesCg.add((ACaseAltStmStmIR) altCg); ACaseAltStmStmIR 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 PExp caseACasesStm(ACasesStm stm, Integer lineno) throws AnalysisException { PExp found = null; for (ACaseAlternativeStm stmt : stm.getCases()) { found = stmt.getResult().apply(THIS, lineno); if (found != null) { break; } } return found; }
e.apply(this);
inACaseAlternativeStm(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.getCtype() != null && !_visitedNodes.contains(node.getCtype())) node.getCtype().apply(this);
@Override public IProofObligationList caseACaseAlternativeStm( ACaseAlternativeStm node, IPOContextStack question) throws AnalysisException { try { IProofObligationList obligations = new ProofObligationList(); obligations.addAll(node.getResult().apply(mainVisitor, question)); return obligations; } catch (Exception e) { throw new POException(node, e.getMessage()); } }
e.apply(this, question);
inACaseAlternativeStm(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.getCtype() != null && !_visitedNodes.contains(node.getCtype())) node.getCtype().apply(this);
@Override public PStm caseACasesStm(ACasesStm stm, Integer lineno) throws AnalysisException { PStm found = findStatementBaseCase(stm, lineno); if (found != null) { return found; } for (ACaseAlternativeStm stmt : stm.getCases()) { found = stmt.getResult().apply(THIS, lineno);// PStmAssistantInterpreter.findStatement(stmt.getResult(), // lineno); if (found != null) { break; } } return found; }
e.apply(this);