/** * Unravelling unused check. * * @param downTo */ public void unusedCheck(Environment downTo) { Environment p = this; while (p != null && p != downTo) { p.unusedCheck(); p = p.outer; } }
@Override public PType caseABlockSimpleBlockStm(ABlockSimpleBlockStm node, TypeCheckInfo question) throws AnalysisException { // Each dcl definition is in scope for later definitions... Environment local = question.env; for (PDefinition d : node.getAssignmentDefs()) { local = new FlatCheckedEnvironment(question.assistantFactory, d, local, question.scope); // cumulative question.assistantFactory.createPDefinitionAssistant().implicitDefinitions(d, local); d.setType(question.assistantFactory.createPTypeAssistant().typeResolve(d.getType(), null, THIS, question)); d.apply(THIS, new TypeCheckInfo(question.assistantFactory, local, question.scope, question.qualifiers, d.getType(), question.returnType)); } // For type checking purposes, the definitions are treated as // local variables. At runtime (below) they have to be treated // more like (updatable) state. PType r = defaultSSimpleBlockStm(node, new TypeCheckInfo(question.assistantFactory, local, question.scope, null, null, question.returnType)); local.unusedCheck(question.env); node.setType(r); return r; }
@Override public PType caseAMapCompMapExp(AMapCompMapExp node, TypeCheckInfo question) throws AnalysisException { PDefinition def = AstFactory.newAMultiBindListDefinition(node.getLocation(), node.getBindings()); def.apply(THIS, question.newConstraint(null)); Environment local = new FlatCheckedEnvironment(question.assistantFactory, def, question.env, question.scope); PExp predicate = node.getPredicate(); TypeCheckInfo pquestion = new TypeCheckInfo(question.assistantFactory, local, question.scope, null, AstFactory.newABooleanBasicType(node.getLocation()), null); if (predicate != null && !question.assistantFactory.createPTypeAssistant().isType(predicate.apply(THIS, pquestion), ABooleanBasicType.class)) { TypeCheckerErrors.report(3118, "Predicate is not boolean", predicate.getLocation(), predicate); } node.setType(node.getFirst().apply(THIS, question.newInfo(local))); local.unusedCheck(); return node.getType(); }
@Override public PType caseAForAllExp(AForAllExp node, TypeCheckInfo question) throws AnalysisException { PDefinition def = AstFactory.newAMultiBindListDefinition(node.getLocation(), node.getBindList()); def.apply(THIS, question.newConstraint(null)); Environment local = new FlatCheckedEnvironment(question.assistantFactory, def, question.env, question.scope); if (!question.assistantFactory.createPTypeAssistant().isType(node.getPredicate().apply(THIS, new TypeCheckInfo(question.assistantFactory, local, question.scope, null, AstFactory.newABooleanBasicType(node.getLocation()), null)), ABooleanBasicType.class)) { TypeCheckerErrors.report(3097, "Predicate is not boolean", node.getPredicate().getLocation(), node.getPredicate()); } local.unusedCheck(); node.setType(AstFactory.newABooleanBasicType(node.getLocation())); return question.assistantFactory.createPTypeAssistant().checkConstraint(question.constraint, node.getType(), node.getLocation()); }
@Override public PType caseAExistsExp(AExistsExp node, TypeCheckInfo question) throws AnalysisException { PDefinition def = AstFactory.newAMultiBindListDefinition(node.getLocation(), node.getBindList()); def.apply(THIS, question.newConstraint(null)); def.setNameScope(NameScope.LOCAL); Environment local = new FlatCheckedEnvironment(question.assistantFactory, def, question.env, question.scope); question = new TypeCheckInfo(question.assistantFactory, local, question.scope, null, AstFactory.newABooleanBasicType(node.getLocation()), null); if (!question.assistantFactory.createPTypeAssistant().isType(node.getPredicate().apply(THIS, question), ABooleanBasicType.class)) { TypeCheckerErrors.report(3089, "Predicate is not boolean", node.getPredicate().getLocation(), node.getPredicate()); } local.unusedCheck(); node.setType(AstFactory.newABooleanBasicType(node.getLocation())); return question.assistantFactory.createPTypeAssistant().checkConstraint(question.constraint, node.getType(), node.getLocation()); }
question = question.newInfo(local); c.setType(c.getResult().apply(rootVisitor, question)); local.unusedCheck(); return c.getType();
@Override public PType caseAForPatternBindStm(AForPatternBindStm node, TypeCheckInfo question) throws AnalysisException { PType stype = node.getExp().apply(THIS, new TypeCheckInfo(question.assistantFactory, question.env, question.scope)); Environment local = question.env; if (question.assistantFactory.createPTypeAssistant().isSeq(stype)) { node.setSeqType(question.assistantFactory.createPTypeAssistant().getSeq(stype)); node.getPatternBind().apply(THIS, new TypeCheckInfo(question.assistantFactory, question.env, question.scope)); List<PDefinition> defs = getDefinitions(node.getPatternBind()); question.assistantFactory.createPDefinitionListAssistant().typeCheck(defs, THIS, new TypeCheckInfo(question.assistantFactory, question.env, question.scope)); local = new FlatCheckedEnvironment(question.assistantFactory, defs, question.env, question.scope); } else { TypeCheckerErrors.report(3223, "Expecting sequence type after 'in'", node.getLocation(), node); } PType rt = node.getStatement().apply(THIS, new TypeCheckInfo(question.assistantFactory, local, question.scope)); local.unusedCheck(); node.setType(rt); return rt; }
@Override public PType caseASetCompSetExp(ASetCompSetExp node, TypeCheckInfo question) throws AnalysisException { PDefinition def = AstFactory.newAMultiBindListDefinition(node.getFirst().getLocation(), node.getBindings()); def.apply(THIS, question.newConstraint(null)); Environment local = new FlatCheckedEnvironment(question.assistantFactory, def, question.env, question.scope); question = new TypeCheckInfo(question.assistantFactory, local, question.scope); PType etype = node.getFirst().apply(THIS, question.newConstraint(null)); PExp predicate = node.getPredicate(); if (predicate != null) { TypeCheckInfo pquestion = new TypeCheckInfo(question.assistantFactory, local, question.scope, null, AstFactory.newABooleanBasicType(node.getLocation()), null); if (!question.assistantFactory.createPTypeAssistant().isType(predicate.apply(THIS, pquestion), ABooleanBasicType.class)) { TypeCheckerErrors.report(3159, "Predicate is not boolean", predicate.getLocation(), predicate); } } local.unusedCheck(); SSetType setType = AstFactory.newASetSetType(node.getLocation(), etype); node.setType(setType); node.setSetType(setType); return setType; }
Environment local = new FlatCheckedEnvironment(question.assistantFactory, defs, question.env, question.scope); node.getStatement().apply(THIS, new TypeCheckInfo(question.assistantFactory, local, question.scope, question.qualifiers)); local.unusedCheck();
@Override public PType caseAForAllStm(AForAllStm node, TypeCheckInfo question) throws AnalysisException { node.setType(node.getSet().apply(THIS, question)); question.assistantFactory.createPPatternAssistant().typeResolve(node.getPattern(), THIS, question); if (question.assistantFactory.createPTypeAssistant().isSet(node.getType())) { SSetType st = question.assistantFactory.createPTypeAssistant().getSet(node.getType()); List<PDefinition> defs = question.assistantFactory.createPPatternAssistant().getDefinitions(node.getPattern(), st.getSetof(), NameScope.LOCAL); Environment local = new FlatCheckedEnvironment(question.assistantFactory, defs, question.env, question.scope); PType rt = node.getStatement().apply(THIS, new TypeCheckInfo(question.assistantFactory, local, question.scope)); local.unusedCheck(); node.setType(rt); return rt; } else { TypeCheckerErrors.report(3219, "For all statement does not contain a set type", node.getLocation(), node); node.setType(AstFactory.newAUnknownType(node.getLocation())); return node.getType(); } }
local.unusedCheck(question.env); return r;
local.unusedCheck(question.env); node.setType(r); return r;
@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 PType caseAExists1Exp(AExists1Exp node, TypeCheckInfo question) throws AnalysisException { node.setDef(AstFactory.newAMultiBindListDefinition(node.getBind().getLocation(), question.assistantFactory.createPBindAssistant().getMultipleBindList(node.getBind()))); node.getDef().apply(THIS, question.newConstraint(null)); Environment local = new FlatCheckedEnvironment(question.assistantFactory, node.getDef(), question.env, question.scope); if (node.getBind() instanceof ATypeBind) { ATypeBind tb = (ATypeBind) node.getBind(); question.assistantFactory.createATypeBindAssistant().typeResolve(tb, THIS, question); } question.qualifiers = null; if (!question.assistantFactory.createPTypeAssistant().isType(node.getPredicate().apply(THIS, new TypeCheckInfo(question.assistantFactory, local, question.scope, null, AstFactory.newABooleanBasicType(node.getLocation()), null)), ABooleanBasicType.class)) { TypeCheckerErrors.report(3088, "Predicate is not boolean", node.getPredicate().getLocation(), node.getPredicate()); } local.unusedCheck(); node.setType(AstFactory.newABooleanBasicType(node.getLocation())); return question.assistantFactory.createPTypeAssistant().checkConstraint(question.constraint, node.getType(), node.getLocation()); }
local.unusedCheck(); node.setType(rt); return rt;
local.unusedCheck(); node.setType(AstFactory.newASeqSeqType(node.getLocation(), etype)); return node.getType();