@Override public IProofObligationList caseASetRangeSetExp(ASetRangeSetExp node, IPOContextStack question) throws AnalysisException { PExp last = node.getLast(); PExp first = node.getFirst(); IProofObligationList obligations = first.apply(mainVisitor, question); obligations.addAll(last.apply(mainVisitor, question)); return obligations; }
@Override public LexNameSet caseASetRangeSetExp(ASetRangeSetExp node, FreeVarInfo info) throws AnalysisException { LexNameSet names = node.getFirst().apply(this, info); names.addAll(node.getLast().apply(this, info)); return names; }
@Override public PExp caseASetRangeSetExp(ASetRangeSetExp exp, Integer lineno) throws AnalysisException { PExp found = findExpressionBaseCase(exp, lineno); if (found != null) { return found; } found = exp.getFirst().apply(THIS, lineno); if (found != null) { return found; } found = exp.getLast().apply(THIS, lineno); if (found != null) { return found; } return null; }
@Override public Value caseASetRangeSetExp(ASetRangeSetExp node, Context ctxt) throws AnalysisException { BreakpointManager.getBreakpoint(node).check(node.getLocation(), ctxt); try { long from = (long) Math.ceil(node.getFirst().apply(VdmRuntime.getExpressionEvaluator(), ctxt).realValue(ctxt)); long to = (long) Math.floor(node.getLast().apply(VdmRuntime.getExpressionEvaluator(), ctxt).realValue(ctxt)); ValueSet set = new ValueSet(); for (long i = from; i <= to; i++) { set.addNoCheck(new IntegerValue(i)); } return new SetValue(set); } catch (ValueException e) { return VdmRuntimeError.abort(node.getLocation(), e); } }
@Override public SExpIR caseASetRangeSetExp(ASetRangeSetExp node, IRInfo question) throws AnalysisException { PType type = node.getType(); PExp firstExp = node.getFirst(); PExp lastExp = node.getLast(); STypeIR typeCg = type.apply(question.getTypeVisitor(), question); SExpIR firstExpCg = firstExp.apply(question.getExpVisitor(), question); SExpIR lastExpCg = lastExp.apply(question.getExpVisitor(), question); ARangeSetExpIR setRange = new ARangeSetExpIR(); setRange.setType(typeCg); setRange.setFirst(firstExpCg); setRange.setLast(lastExpCg); return setRange; }
@Override public PType caseASetRangeSetExp(ASetRangeSetExp node, TypeCheckInfo question) throws AnalysisException { PExp first = node.getFirst(); PExp last = node.getLast(); question.qualifiers = null; node.setFtype(first.apply(THIS, question.newConstraint(null))); question.qualifiers = null; node.setLtype(last.apply(THIS, question.newConstraint(null))); PType ftype = node.getFtype(); PType ltype = node.getLtype(); if (!question.assistantFactory.createPTypeAssistant().isNumeric(ftype)) { TypeCheckerErrors.report(3166, "Set range type must be a number", first.getLocation(), ftype); ftype = AstFactory.newAIntNumericBasicType(node.getLocation()); } SNumericBasicType ntype = question.assistantFactory.createPTypeAssistant().getNumeric(ftype); if (question.assistantFactory.createSNumericBasicTypeAssistant().getWeight(ntype) > 1) { ftype = AstFactory.newAIntNumericBasicType(node.getLocation()); // Caused by ceiling/floor } if (!question.assistantFactory.createPTypeAssistant().isNumeric(ltype)) { TypeCheckerErrors.report(3167, "Set range type must be a number", last.getLocation(), ltype); } node.setType(AstFactory.newASetSetType(first.getLocation(), ftype)); return question.assistantFactory.createPTypeAssistant().possibleConstraint(question.constraint, node.getType(), node.getLocation()); }