@Override public PType caseAPreOpExp(APreOpExp node, TypeCheckInfo question) throws AnalysisException { node.setType(node.getExpression().apply(THIS, question.newConstraint(null))); return node.getType(); }
@Override public PType caseAPostOpExp(APostOpExp node, TypeCheckInfo question) throws AnalysisException { node.setType(node.getPostexpression().apply(THIS, question.newConstraint(null))); return node.getType(); }
@Override public PType caseAPreExp(APreExp node, TypeCheckInfo question) throws AnalysisException { node.getFunction().apply(THIS, question.newConstraint(null)); for (PExp a : node.getArgs()) { question.qualifiers = null; a.apply(THIS, question.newConstraint(null)); } node.setType(AstFactory.newABooleanBasicType(node.getLocation())); return node.getType(); }
@Override public PType caseADivNumericBinaryExp(ADivNumericBinaryExp node, TypeCheckInfo question) throws AnalysisException { checkNumeric(node, THIS, question.newConstraint(null)); node.setType(AstFactory.newAIntNumericBasicType(node.getLocation())); return node.getType(); }
@Override public PType caseADivideNumericBinaryExp( ADivideNumericBinaryExp node, TypeCheckInfo question) throws AnalysisException { checkNumeric(node, THIS, question.newConstraint(null)); node.setType(AstFactory.newARealNumericBasicType(node.getLocation())); return node.getType(); }
@Override public PType caseAModNumericBinaryExp(AModNumericBinaryExp node, TypeCheckInfo question) throws AnalysisException { checkNumeric(node, THIS, question.newConstraint(null)); node.setType(AstFactory.newAIntNumericBasicType(node.getLocation())); return node.getType(); }
@Override public PType caseARemNumericBinaryExp(ARemNumericBinaryExp node, TypeCheckInfo question) throws AnalysisException { checkNumeric(node, THIS, question.newConstraint(null)); node.setType(AstFactory.newAIntNumericBasicType(node.getLocation())); return node.getType(); }
@Override public PType caseAGreaterNumericBinaryExp( AGreaterNumericBinaryExp node, TypeCheckInfo question) throws AnalysisException { checkOrdered(node, THIS, question.newConstraint(null)); node.setType(AstFactory.newABooleanBasicType(node.getLocation())); return question.assistantFactory.createPTypeAssistant().checkConstraint(question.constraint, node.getType(), node.getLocation()); }
@Override public PType caseAGreaterEqualNumericBinaryExp( AGreaterEqualNumericBinaryExp node, TypeCheckInfo question) throws AnalysisException { checkOrdered(node, THIS, question.newConstraint(null)); node.setType(AstFactory.newABooleanBasicType(node.getLocation())); return question.assistantFactory.createPTypeAssistant().checkConstraint(question.constraint, node.getType(), node.getLocation()); }
@Override public PType caseAFloorUnaryExp(AFloorUnaryExp node, TypeCheckInfo question) throws AnalysisException { PExp exp = node.getExp(); question.qualifiers = null; if (!question.assistantFactory.createPTypeAssistant().isNumeric(exp.apply(THIS, question.newConstraint(null)))) { TypeCheckerErrors.report(3096, "Argument to floor is not numeric", node.getLocation(), node); } node.setType(AstFactory.newAIntNumericBasicType(node.getLocation())); return node.getType(); }
@Override public PType caseACardinalityUnaryExp(ACardinalityUnaryExp node, TypeCheckInfo question) throws AnalysisException { PExp exp = node.getExp(); question.qualifiers = null; if (!question.assistantFactory.createPTypeAssistant().isSet(exp.apply(THIS, question.newConstraint(null)))) { TypeCheckerErrors.report(3067, "Argument of 'card' is not a set", exp.getLocation(), exp); } node.setType(AstFactory.newANatNumericBasicType(node.getLocation())); return question.assistantFactory.createPTypeAssistant().possibleConstraint(question.constraint, node.getType(), node.getLocation()); }
@Override public PType caseAMkBasicExp(AMkBasicExp node, TypeCheckInfo question) throws AnalysisException { PType argtype = node.getArg().apply(THIS, question.newConstraint(null)); if (!(node.getType() instanceof ATokenBasicType) && !question.assistantFactory.createPTypeAssistant().equals(argtype, node.getType())) { TypeCheckerErrors.report(3125, "Argument of mk_" + node.getType() + " is the wrong type", node.getLocation(), node); } return question.assistantFactory.createPTypeAssistant().checkConstraint(question.constraint, node.getType(), node.getLocation()); }
@Override public PType caseALenUnaryExp(ALenUnaryExp node, TypeCheckInfo question) throws AnalysisException { PExp exp = node.getExp(); question.qualifiers = null; PType etype = exp.apply(THIS, question.newConstraint(null)); if (!question.assistantFactory.createPTypeAssistant().isSeq(etype)) { TypeCheckerErrors.report(3116, "Argument to 'len' is not a sequence", node.getLocation(), node); } node.setType(AstFactory.newANatNumericBasicType(node.getLocation())); return question.assistantFactory.createPTypeAssistant().possibleConstraint(question.constraint, node.getType(), node.getLocation()); }
@Override public PType caseANotUnaryExp(ANotUnaryExp node, TypeCheckInfo question) throws AnalysisException { PExp exp = node.getExp(); question.qualifiers = null; PType t = exp.apply(THIS, question.newConstraint(null)); if (!question.assistantFactory.createPTypeAssistant().isType(t, ABooleanBasicType.class)) { TypeCheckerErrors.report(3137, "Not expression is not a boolean", node.getLocation(), node); } node.setType(AstFactory.newABooleanBasicType(node.getLocation())); return question.assistantFactory.createPTypeAssistant().checkConstraint(question.constraint, node.getType(), node.getLocation()); }
@Override public PType caseAHeadUnaryExp(AHeadUnaryExp node, TypeCheckInfo question) throws AnalysisException { PExp exp = node.getExp(); question.qualifiers = null; PType etype = exp.apply(THIS, question.newConstraint(null)); if (!question.assistantFactory.createPTypeAssistant().isSeq(etype)) { TypeCheckerErrors.report(3104, "Argument to 'hd' is not a sequence", node.getLocation(), node); node.setType(AstFactory.newAUnknownType(node.getLocation())); return node.getType(); } node.setType(question.assistantFactory.createPTypeAssistant().getSeq(etype).getSeqof()); return node.getType(); }
@Override public PType caseAMapDomainUnaryExp(AMapDomainUnaryExp node, TypeCheckInfo question) throws AnalysisException { PExp exp = node.getExp(); question.qualifiers = null; PType etype = exp.apply(THIS, question.newConstraint(null)); if (!question.assistantFactory.createPTypeAssistant().isMap(etype)) { TypeCheckerErrors.report(3120, "Argument to 'dom' is not a map", node.getLocation(), node); node.setType(AstFactory.newAUnknownType(node.getLocation())); return node.getType(); } SMapType mt = question.assistantFactory.createPTypeAssistant().getMap(etype); node.setType(AstFactory.newASetSetType(node.getLocation(), mt.getFrom())); return node.getType(); }
@Override public PType caseAMapRangeUnaryExp(AMapRangeUnaryExp node, TypeCheckInfo question) throws AnalysisException { PExp exp = node.getExp(); question.qualifiers = null; PType etype = exp.apply(THIS, question.newConstraint(null)); if (!question.assistantFactory.createPTypeAssistant().isMap(etype)) { TypeCheckerErrors.report(3122, "Argument to 'rng' is not a map", node.getLocation(), node); node.setType(AstFactory.newAUnknownType(node.getLocation())); return node.getType(); } SMapType mt = question.assistantFactory.createPTypeAssistant().getMap(etype); node.setType(AstFactory.newASetSetType(node.getLocation(), mt.getTo())); return node.getType(); }
@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()); }