@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 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()); }