public boolean isIntegerType(PExp exp) { PType type = exp.getType(); // Expressions like 1.0 are considered real literal expressions // of type NatOneNumericBasicType return (type instanceof ANatOneNumericBasicType || type instanceof ANatNumericBasicType || type instanceof AIntNumericBasicType) && !(exp instanceof ARealLiteralExp); }
@Override public void caseACompBinaryExp(ACompBinaryExp node) throws AnalysisException { PTypeAssistantTC typeAssistant = info.getTcFactory().createPTypeAssistant(); if(typeAssistant.isMap(node.getLeft().getType())) { // Supported } else if(typeAssistant.isFunction(node.getLeft().getType())) { info.addUnsupportedNode(node, "Function composition is not supported"); } }
private IProofObligationList handleNumericBinaryExpression(SNumericBinaryExp node, IPOContextStack question) throws AnalysisException { IProofObligationList obligations = new ProofObligationList(); PExp[] leftRight = getLeftRight(node); PExp left = leftRight[LEFT]; PExp right = leftRight[RIGHT]; PType ltype = left.getType(); PType rtype = right.getType(); if (left.getLocation().getStartLine() == 2792) { System.out.println("fd"); } handleBinExpSubNode(question, obligations, left, ltype); handleBinExpSubNode(question, obligations, right , rtype); obligations.addAll(left.apply(mainVisitor, question)); obligations.addAll(right.apply(mainVisitor, question)); return obligations; }
@Override public IProofObligationList caseAPlusPlusBinaryExp(APlusPlusBinaryExp node, IPOContextStack question) throws AnalysisException { IProofObligationList obligations = handleBinaryExpression(node, question); PType lType = node.getLeft().getType(); if (aF.createPTypeAssistant().isSeq(lType)) { obligations.add(new org.overture.pog.obligation.SeqModificationObligation(node, question, aF)); } return obligations; }
@Override public void caseAStarStarBinaryExp(AStarStarBinaryExp node) throws AnalysisException { PTypeAssistantTC typeAssistant = info.getTcFactory().createPTypeAssistant(); PType lType = node.getLeft().getType(); if(typeAssistant.isMap(lType)) { // Supported } else if(typeAssistant.isFunction(lType)){ info.addUnsupportedNode(node, "Function composition not supported"); } // else it's numeric (the power operator), which is supported. }
public PExp caseAMapletPatternMaplet(AMapletPatternMaplet node) throws AnalysisException { AMapletExp maplet = new AMapletExp(); PExp from = node.getFrom().apply(this).clone(); maplet.setLeft(from); PExp to = node.getTo().apply(this).clone(); maplet.setRight(to); maplet.setType(AstFactory.newAMapMapType(null, from.getType().clone(), to.getType().clone())); return maplet; }
public SExpIR handleQuantifier(PExp node, List<PMultipleBind> bindings, PExp predicate, SQuantifierExpIR quantifier, IRInfo question, String nodeStr) throws AnalysisException { LinkedList<SMultipleBindIR> bindingsCg = new LinkedList<SMultipleBindIR>(); for (PMultipleBind multipleBind : bindings) { SMultipleBindIR multipleBindCg = multipleBind.apply(question.getMultipleBindVisitor(), question); if (multipleBindCg != null) { bindingsCg.add(multipleBindCg); } } PType type = node.getType(); STypeIR typeCg = type.apply(question.getTypeVisitor(), question); SExpIR predicateCg = predicate.apply(question.getExpVisitor(), question); quantifier.setType(typeCg); quantifier.setBindList(bindingsCg); quantifier.setPredicate(predicateCg); return quantifier; }
@Override public PType caseANotEqualBinaryExp(ANotEqualBinaryExp node, TypeCheckInfo question) throws AnalysisException { node.getLeft().apply(THIS, question.newConstraint(null)); node.getRight().apply(THIS, question.newConstraint(null)); if (question.assistantFactory.createPTypeAssistant().isUnion(node.getLeft().getType())) { IQuestion<TypeCheckInfo> mEqC = question.assistantFactory.getMultipleEqualityChecker(); node.getLeft().getType().apply(mEqC,question); } if (question.assistantFactory.createPTypeAssistant().isUnion(node.getRight().getType())) { IQuestion<TypeCheckInfo> mEqC = question.assistantFactory.getMultipleEqualityChecker(); node.getRight().apply(mEqC,question); } if (!question.assistantFactory.getTypeComparator().compatible(node.getLeft().getType(), node.getRight().getType())) { TypeCheckerErrors.report(3136, "Left and right of '<>' different types", node.getLocation(), node); TypeCheckerErrors.detail2("Left", node.getLeft().getType(), "Right", node.getRight().getType()); } node.setType(AstFactory.newABooleanBasicType(node.getLocation())); return question.assistantFactory.createPTypeAssistant().checkConstraint(question.constraint, node.getType(), node.getLocation()); }
@Override public IProofObligationList caseATailUnaryExp(ATailUnaryExp node, IPOContextStack question) throws AnalysisException { IProofObligationList obligations = node.getExp().apply(mainVisitor, question); if (!aF.createPTypeAssistant().isType(node.getExp().getType(), ASeq1SeqType.class)) { obligations.add(new NonEmptySeqObligation(node.getExp(), question, aF)); } return obligations; }
private AValueDefinition buildValueDef(PExp exp, String name) { AValueDefinition valDef = new AValueDefinition(); valDef.setType(exp.getType().clone()); valDef.setExpression(exp.clone()); AIdentifierPattern pattern = new AIdentifierPattern(); pattern.setName(new LexNameToken(null, name, null)); valDef.setPattern(pattern); return valDef; }
@Override public LexNameSet caseAApplyExp(AApplyExp node, FreeVarInfo info) throws AnalysisException { LexNameSet names = new LexNameSet(); if (node.getRoot() instanceof AVariableExp && node.getRoot().getType() != null && af.createPTypeAssistant().isFunction(node.getRoot().getType())) { // If this is a global call, then we depend on the function AVariableExp v = (AVariableExp)node.getRoot(); if (info.globals.findName(v.getName(), NameScope.NAMESANDSTATE) != null) { names.add(v.getName()); } } for (PExp exp: node.getArgs()) { names.addAll(exp.apply(this, info)); } return names; }
private void checkNumeric(SNumericBinaryExp node, IQuestionAnswer<TypeCheckInfo, PType> rootVisitor, TypeCheckInfo question) throws AnalysisException { node.getLeft().apply(rootVisitor, question.newConstraint(null)); node.getRight().apply(rootVisitor, question.newConstraint(null)); if (!question.assistantFactory.createPTypeAssistant().isNumeric(node.getLeft().getType())) { TypeCheckerErrors.report(3139, "Left hand of " + node.getOp() + " is not numeric", node.getLocation(), node); TypeCheckerErrors.detail("Actual", node.getLeft().getType()); node.getLeft().setType(AstFactory.newARealNumericBasicType(node.getLocation())); } if (!question.assistantFactory.createPTypeAssistant().isNumeric(node.getRight().getType())) { TypeCheckerErrors.report(3140, "Right hand of " + node.getOp() + " is not numeric", node.getLocation(), node); TypeCheckerErrors.detail("Actual", node.getRight().getType()); node.getRight().setType(AstFactory.newARealNumericBasicType(node.getLocation())); } }
@Override public IProofObligationList caseAStarStarBinaryExp(AStarStarBinaryExp node, IPOContextStack question) throws AnalysisException { IProofObligationList obligations = new ProofObligationList(); PExp lExp = node.getLeft(); PType lType = lExp.getType(); if (aF.createPTypeAssistant().isFunction(lType)) { ILexNameToken preName = getPreName(lExp); if (preName == null || !preName.equals(NO_PRECONDITION)) { obligations.add(new org.overture.pog.obligation.FuncIterationObligation(node, preName, question, aF)); } } if (aF.createPTypeAssistant().isMap(lType)) { obligations.add(new MapIterationObligation(node, question, aF)); } return obligations; }
private void checkOrdered(SNumericBinaryExp node, IQuestionAnswer<TypeCheckInfo, PType> rootVisitor, TypeCheckInfo question) throws AnalysisException { node.getLeft().apply(rootVisitor, question.newConstraint(null)); node.getRight().apply(rootVisitor, question.newConstraint(null)); if (!question.assistantFactory.createPTypeAssistant().isOrdered(node.getLeft().getType(), node.getLocation())) { TypeCheckerErrors.report(3139, "Left hand of " + node.getOp() + " is not ordered", node.getLocation(), node); TypeCheckerErrors.detail("Actual", node.getLeft().getType()); node.getLeft().setType(AstFactory.newARealNumericBasicType(node.getLocation())); } if (!question.assistantFactory.createPTypeAssistant().isOrdered(node.getRight().getType(), node.getLocation())) { TypeCheckerErrors.report(3140, "Right hand of " + node.getOp() + " is not ordered", node.getLocation(), node); TypeCheckerErrors.detail("Actual", node.getRight().getType()); node.getRight().setType(AstFactory.newARealNumericBasicType(node.getLocation())); } }
@Override public IProofObligationList caseANarrowExp(ANarrowExp node, IPOContextStack question) throws AnalysisException { IProofObligationList obligations = new ProofObligationList(); PType expected = node.getTypedef() == null ? node.getBasicType() : aF.createPDefinitionAssistant().getType(node.getTypedef()); question.noteType(node.getTest(), expected); if (!aF.getTypeComparator().isSubType(node.getTest().getType(), expected)) { TypeCompatibilityObligation sto = TypeCompatibilityObligation.newInstance(node.getTest(), expected, node.getTest().getType(), question, aF); if (sto != null) { obligations.add(sto); } } obligations.addAll(node.getTest().apply(rootVisitor, question)); return obligations; }
private PExp alt2Exp(ACaseAlternative alt, ACasesExp exp, IPogAssistantFactory assistantFactory) throws AnalysisException { if (assistantFactory.createPPatternAssistant().isSimple(alt.getPattern())) { AEqualsBinaryExp equalsExp = AstExpressionFactory.newAEqualsBinaryExp(exp.getExpression().clone(), patternToExp(alt.getPattern().clone())); return equalsExp; } else { PExp matching = patternToExp(alt.getPattern().clone()); AExistsExp existsExp = new AExistsExp(); ATypeMultipleBind tbind = new ATypeMultipleBind(); List<PPattern> plist = new LinkedList<PPattern>(); plist.add(alt.getPattern().clone()); tbind.setPlist(plist); tbind.setType(exp.getExpression().getType().clone()); List<PMultipleBind> bindList = new LinkedList<PMultipleBind>(); bindList.add(tbind); existsExp.setBindList(bindList); AEqualsBinaryExp equalsExp = AstExpressionFactory.newAEqualsBinaryExp(exp.getExpression().clone(), matching); existsExp.setPredicate(equalsExp); return existsExp; } }
@Override public PType caseANotInSetBinaryExp(ANotInSetBinaryExp node, TypeCheckInfo question) throws AnalysisException { TypeCheckInfo noConstraint = question.newConstraint(null); PType ltype = node.getLeft().apply(THIS, noConstraint); PType rtype = node.getRight().apply(THIS, noConstraint); if (!question.assistantFactory.createPTypeAssistant().isSet(node.getRight().getType())) { TypeCheckerErrors.report(3138, "Argument of 'not in set' is not a set", node.getLocation(), node); TypeCheckerErrors.detail("Actual", node.getRight().getType()); } else { SSetType stype = question.assistantFactory.createPTypeAssistant().getSet(rtype); if (!question.assistantFactory.getTypeComparator().compatible(stype.getSetof(), ltype)) { TypeCheckerErrors.report(3320, "'not in set' expression is always true", node.getLocation(), node); TypeCheckerErrors.detail2("Element", ltype, "Set", stype); } } node.setType(AstFactory.newABooleanBasicType(node.getLocation())); return question.assistantFactory.createPTypeAssistant().checkConstraint(question.constraint, node.getType(), node.getLocation()); }
@Override public SExpIR caseAStarStarBinaryExp(AStarStarBinaryExp node, IRInfo question) throws AnalysisException { PTypeAssistantTC assist = question.getTcFactory().createPTypeAssistant(); PType lType = node.getLeft().getType(); if(assist.isMap(lType)) { return question.getExpAssistant().handleBinaryExp(node, new AMapIterationBinaryExpIR(), question); } else if(assist.isFunction(lType)) { return question.getExpAssistant().handleBinaryExp(node, new AFuncIterationBinaryExpIR(), question); } else { // So it must be numeric return question.getExpAssistant().handleBinaryExp(node, new APowerNumericBinaryExpIR(), question); } }
public FuncIterationObligation(AStarStarBinaryExp exp, ILexNameToken preName, IPOContextStack ctxt, IPogAssistantFactory assistantFactory) throws AnalysisException { super(exp, POType.FUNC_ITERATION, ctxt, exp.getLocation(), assistantFactory); // n > 1 AGreaterNumericBinaryExp gTExp = AstExpressionFactory.newAGreaterNumericBinaryExp(exp.getRight().clone(), getIntLiteral(1)); // forall n :T & P(X) AForAllExp forAllExp = new AForAllExp(); ILexNameToken arg = getUnique("arg"); List<PMultipleBind> bindList = getMultipleTypeBindList(assistantFactory.createPTypeAssistant().getNumeric(exp.getRight().getType().clone()), arg); forAllExp.setBindList(bindList); forAllExp.setPredicate(getPredicate(exp.clone(), preName.clone(), arg)); // n > 1 => forall n :T & P(X) AImpliesBooleanBinaryExp impliesExp = AstExpressionFactory.newAImpliesBooleanBinaryExp(gTExp, forAllExp); stitch = impliesExp.clone(); valuetree.setPredicate(ctxt.getPredWithContext(impliesExp)); }
@Override public PType caseAInSetBinaryExp(AInSetBinaryExp node, TypeCheckInfo question) throws AnalysisException { TypeCheckInfo noConstraint = question.newConstraint(null); PType ltype = node.getLeft().apply(THIS, noConstraint); PType rtype = node.getRight().apply(THIS, noConstraint); if (!question.assistantFactory.createPTypeAssistant().isSet(node.getRight().getType())) { TypeCheckerErrors.report(3110, "Argument of 'in set' is not a set", node.getLocation(), node); TypeCheckerErrors.detail("Actual", rtype); } else { SSetType stype = question.assistantFactory.createPTypeAssistant().getSet(rtype); if (!question.assistantFactory.getTypeComparator().compatible(stype.getSetof(), ltype)) { TypeCheckerErrors.report(3319, "'in set' expression is always false", node.getLocation(), node); TypeCheckerErrors.detail2("Element", ltype, "Set", stype); } } node.setType(AstFactory.newABooleanBasicType(node.getLocation())); return question.assistantFactory.createPTypeAssistant().checkConstraint(question.constraint, node.getType(), node.getLocation()); }