@Override public PType caseADurationStm(ADurationStm node, TypeCheckInfo question) throws AnalysisException { PDefinition encl = question.env.getEnclosingDefinition(); if (encl != null && encl.getAccess().getPure()) { TypeCheckerErrors.report(3346, "Cannot use duration in pure operations", node.getLocation(), node); } Environment newEnv = new FlatEnvironment(question.assistantFactory, question.env, true); TypeCheckInfo functional = question.newInfo(newEnv); PType argType = node.getDuration().apply(THIS, functional); if (!question.assistantFactory.getTypeComparator().compatible(AstFactory.newANatNumericBasicType(node.getLocation()), argType)) { TypeCheckerErrors.report(3281, "Arguments to duration must be a nat", node.getLocation(), node); TypeCheckerErrors.detail("Actual", argType); } return node.getStatement().apply(THIS, question); }
@Override public Value caseADurationStm(ADurationStm node, Context ctxt) throws AnalysisException { node.getLocation().hit(); node.getDuration().getLocation().hit(); ISchedulableThread me = BasicSchedulableThread.getThread(Thread.currentThread()); if (me.inOuterTimestep()) { // Already in a timed step, so ignore nesting return node.getStatement().apply(VdmRuntime.getStatementEvaluator(), ctxt); } else { // We disable the swapping and time (RT) as duration evaluation should be "free". long step; try { ctxt.threadState.setAtomic(true); step = node.getDuration().apply(VdmRuntime.getStatementEvaluator(), ctxt).natValue(ctxt); } finally { ctxt.threadState.setAtomic(false); } me.inOuterTimestep(true); Value rv = node.getStatement().apply(VdmRuntime.getStatementEvaluator(), ctxt); me.inOuterTimestep(false); me.duration(step, ctxt, node.getLocation()); return rv; } }