@Override public void caseAForIndexStm(AForIndexStm node) throws AnalysisException { if (!proceed(node)) { return; } if (node.getFrom() != null) { node.getFrom().apply(this); } if (node.getTo() != null) { node.getTo().apply(this); } if (node.getBy() != null) { node.getBy().apply(this); } ILexNameToken var = node.getVar(); openLoop(var, null, node.getStatement()); node.getStatement().apply(this); localDefsInScope.remove(var); }
@Override public PType caseAForIndexStm(AForIndexStm node, TypeCheckInfo question) throws AnalysisException { PType ft = node.getFrom().apply(THIS, question); PType tt = node.getTo().apply(THIS, question); if (!question.assistantFactory.createPTypeAssistant().isNumeric(ft)) { TypeCheckerErrors.report(3220, "From type is not numeric", node.getLocation(), node); } if (!question.assistantFactory.createPTypeAssistant().isNumeric(tt)) { TypeCheckerErrors.report(3221, "To type is not numeric", node.getLocation(), node); } if (node.getBy() != null) { PType bt = node.getBy().apply(THIS, question); if (!question.assistantFactory.createPTypeAssistant().isNumeric(bt)) { TypeCheckerErrors.report(3222, "By type is not numeric", node.getLocation(), node); } } PDefinition vardef = AstFactory.newALocalDefinition(node.getVar().getLocation(), node.getVar(), NameScope.LOCAL, ft); Environment local = new FlatCheckedEnvironment(question.assistantFactory, vardef, question.env, question.scope); PType rt = node.getStatement().apply(THIS, new TypeCheckInfo(question.assistantFactory, local, question.scope)); local.unusedCheck(); node.setType(rt); return rt; }
@Override public SStmIR caseAForIndexStm(AForIndexStm node, IRInfo question) throws AnalysisException { ILexNameToken var = node.getVar(); PExp from = node.getFrom(); PExp to = node.getTo(); PExp by = node.getBy(); PStm stm = node.getStatement(); String varCg = var.getName(); SExpIR fromCg = from.apply(question.getExpVisitor(), question); SExpIR toCg = to.apply(question.getExpVisitor(), question); SExpIR byCg = by != null ? by.apply(question.getExpVisitor(), question) : null; SStmIR bodyCg = stm.apply(question.getStmVisitor(), question); AForIndexStmIR forStm = new AForIndexStmIR(); forStm.setVar(varCg); forStm.setFrom(fromCg); forStm.setTo(toCg); forStm.setBy(byCg); forStm.setBody(bodyCg); return forStm; }
evalContext.put(node.getVar(), new IntegerValue(value)); Value rv = node.getStatement().apply(VdmRuntime.getStatementEvaluator(), evalContext);