/** * Called by the {@link AStarStarBinaryExp} node from {@link AStarStarBinaryExp#apply(IPOFAnalysis)}. * @param node the calling {@link AStarStarBinaryExp} node */ public void caseAStarStarBinaryExp(AStarStarBinaryExp node) throws AnalysisException { _visitedNodes.add(node); inAStarStarBinaryExp(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this); } if(node.getLeft() != null && !_visitedNodes.contains(node.getLeft())) { node.getLeft().apply(this); } if(node.getOp() != null ) { node.getOp().apply(this); } if(node.getRight() != null && !_visitedNodes.contains(node.getRight())) { node.getRight().apply(this); } outAStarStarBinaryExp(node); }
/** * Returns a deep clone of this {@link AStarStarBinaryExp} node. * @return a deep clone of this {@link AStarStarBinaryExp} node */ public AStarStarBinaryExp clone() { return new AStarStarBinaryExp( _type, _location, cloneNode(_left), cloneNode(_op), cloneNode(_right) ); }
node.getLeft().apply(THIS, noConstraint); node.getRight().apply(THIS, noConstraint); PType ltype = node.getLeft().getType(); PType rtype = node.getRight().getType(); TypeCheckerErrors.report(3170, "Map iterator expects nat as right hand arg", node.getRight().getLocation(), rtype); if (!question.assistantFactory.createPTypeAssistant().isNumeric(rtype)) TypeCheckerErrors.report(3171, "Function iterator expects nat as right hand arg", node.getRight().getLocation(), rtype); if (!question.assistantFactory.createPTypeAssistant().isNumeric(rtype)) TypeCheckerErrors.report(3172, "'**' expects number as right hand arg", node.getRight().getLocation(), rtype); TypeCheckerErrors.report(3173, "First arg of '**' must be a map, function or number", node.getLocation(), node); node.setType(AstFactory.newAUnknownType(node.getLocation())); return node.getType(); node.setType(ltype); return ltype;
node.getLocation().hit(); // Mark as covered Value lv = node.getLeft().apply(VdmRuntime.getExpressionEvaluator(), ctxt).deref(); Value rv = node.getRight().apply(VdmRuntime.getExpressionEvaluator(), ctxt); VdmRuntimeError.abort(node.getLocation(), 4133, "Map range is not a subset of its domain: " + k, ctxt); VdmRuntimeError.abort(node.getLocation(), 4030, "Duplicate map keys have different values: " + k, ctxt); return VdmRuntimeError.abort(node.getLocation(), 4031, "First arg of '**' must be a map, function or number", ctxt); } catch (ValueException e) return VdmRuntimeError.abort(node.getLocation(), e);
private PExp getPredicate(AStarStarBinaryExp exp, ILexNameToken preName, ILexNameToken arg) { if (preName != null) { return getImplies(getVarExp(preName), exp.getLeft(), preName, arg); } else { // if no existing pre_f, build it AApplyExp applyExp = new AApplyExp(); ILexNameToken prename = new LexNameToken("", "pre_", null); applyExp.setRoot(getVarExp(prename)); List<PExp> argList = new LinkedList<PExp>(); argList.add(exp.getLeft()); applyExp.setArgs(argList); return getImplies(applyExp, exp.getLeft(), prename, arg); } }
public MapIterationObligation(AStarStarBinaryExp exp, IPOContextStack ctxt, IPogAssistantFactory af) throws AnalysisException super(exp, POType.MAP_ITERATION, ctxt, exp.getLocation(), af); AIntLiteralExp one = getIntLiteral(1); orExp.setLeft(getEqualsExp(exp.clone(), zero)); AOrBooleanBinaryExp orExp2 = new AOrBooleanBinaryExp(); orExp2.setLeft(getEqualsExp(exp.clone(), one)); rng.setExp(exp.getLeft().clone()); AMapDomainUnaryExp dom = new AMapDomainUnaryExp(); dom.setExp(exp.getLeft().clone()); ASubsetBinaryExp subset = new ASubsetBinaryExp(); subset.setLeft(rng);
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)); }
public static AStarStarBinaryExp newAStarStarBinaryExp(PExp left, LexToken op, PExp right) { AStarStarBinaryExp result = new AStarStarBinaryExp(); initExpressionBinary(result, left, op, right); return result; }
@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. }
/** * Called by the {@link AStarStarBinaryExp} node from {@link AStarStarBinaryExp#apply(IAnalysis)}. * @param node the calling {@link AStarStarBinaryExp} node */ public void caseAStarStarBinaryExp(AStarStarBinaryExp node) throws AnalysisException { _visitedNodes.add(node); inAStarStarBinaryExp(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this); } if(node.getLeft() != null && !_visitedNodes.contains(node.getLeft())) { node.getLeft().apply(this); } if(node.getOp() != null ) { node.getOp().apply(this); } if(node.getRight() != null && !_visitedNodes.contains(node.getRight())) { node.getRight().apply(this); } outAStarStarBinaryExp(node); }
@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; }
/** * Creates a deep clone of this {@link AStarStarBinaryExp} node while putting all * old node-new node relations in the map {@code oldToNewMap}. * @param oldToNewMap the map filled with the old node-new node relation * @return a deep clone of this {@link AStarStarBinaryExp} node */ public AStarStarBinaryExp clone(Map<INode,INode> oldToNewMap) { AStarStarBinaryExp node = new AStarStarBinaryExp( _type, _location, cloneNode(_left, oldToNewMap), cloneNode(_op, oldToNewMap), cloneNode(_right, oldToNewMap) ); oldToNewMap.put(this, node); return node; }
/** * Called by the {@link AStarStarBinaryExp} node from {@link AStarStarBinaryExp#apply(IAnalysis)}. * @param node the calling {@link AStarStarBinaryExp} node */ public void caseAStarStarBinaryExp(AStarStarBinaryExp node, Q question) throws AnalysisException { _visitedNodes.add(node); inAStarStarBinaryExp(node, question); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this, question); } if(node.getLeft() != null && !_visitedNodes.contains(node.getLeft())) { node.getLeft().apply(this, question); } if(node.getOp() != null ) { node.getOp().apply(this, question); } if(node.getRight() != null && !_visitedNodes.contains(node.getRight())) { node.getRight().apply(this, question); } outAStarStarBinaryExp(node, question); }
@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); } }
/** * Called by the {@link AStarStarBinaryExp} node from {@link AStarStarBinaryExp#apply(IAnalysis)}. * @param node the calling {@link AStarStarBinaryExp} node */ public A caseAStarStarBinaryExp(AStarStarBinaryExp node) throws AnalysisException { _visitedNodes.add(node); A retVal = createNewReturnValue(node); mergeReturns(retVal,inAStarStarBinaryExp(node)); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { mergeReturns(retVal,node.getType().apply(this)); } if(node.getLeft() != null && !_visitedNodes.contains(node.getLeft())) { mergeReturns(retVal,node.getLeft().apply(this)); } if(node.getOp() != null ) { mergeReturns(retVal,node.getOp().apply(this)); } if(node.getRight() != null && !_visitedNodes.contains(node.getRight())) { mergeReturns(retVal,node.getRight().apply(this)); } mergeReturns(retVal,outAStarStarBinaryExp(node)); return retVal; }
/** * Called by the {@link AStarStarBinaryExp} node from {@link AStarStarBinaryExp#apply(IAnalysis)}. * @param node the calling {@link AStarStarBinaryExp} node */ public A caseAStarStarBinaryExp(AStarStarBinaryExp node, Q question) throws AnalysisException { _visitedNodes.add(node); A retVal = createNewReturnValue(node, question); mergeReturns(retVal,inAStarStarBinaryExp(node, question)); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { mergeReturns(retVal,node.getType().apply(this, question)); } if(node.getLeft() != null && !_visitedNodes.contains(node.getLeft())) { mergeReturns(retVal,node.getLeft().apply(this, question)); } if(node.getOp() != null ) { mergeReturns(retVal,node.getOp().apply(this, question)); } if(node.getRight() != null && !_visitedNodes.contains(node.getRight())) { mergeReturns(retVal,node.getRight().apply(this, question)); } mergeReturns(retVal,outAStarStarBinaryExp(node, question)); return retVal; }