/** * Called by the {@link AForAllExp} node from {@link AForAllExp#apply(IAnalysis)}. * @param node the calling {@link AForAllExp} node */ public void caseAForAllExp(AForAllExp node) throws AnalysisException { _visitedNodes.add(node); inAForAllExp(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this); } { List<PMultipleBind> copy = new ArrayList<PMultipleBind>(node.getBindList()); for( PMultipleBind e : copy) { if(!_visitedNodes.contains(e)) { e.apply(this); } } } if(node.getPredicate() != null && !_visitedNodes.contains(node.getPredicate())) { node.getPredicate().apply(this); } outAForAllExp(node); }
protected AForAllExp getSuperContext(PExp stitch) { AForAllExp forAllExp = new AForAllExp(); forAllExp.setType(new ABooleanBasicType()); forAllExp.setBindList(cloneBinds(bindings)); forAllExp.setPredicate(stitch); return forAllExp; }
@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()); }
/** * Creates a new complete constructor {@code AForAllExp} node with the given nodes as children. * @deprecated This method should not be used, use AstFactory instead. * The basic child nodes are removed from their previous parents. * @param bindList_ the {@link NodeList} node for the {@code bindList} child of this {@link AForAllExp} node * @param predicate_ the {@link PExp} node for the {@code predicate} child of this {@link AForAllExp} node */ public AForAllExp(PType type_, ILexLocation location_, List<? extends PMultipleBind> bindList_, PExp predicate_) { super(type_,location_); this.setBindList(bindList_); this.setPredicate(predicate_); }
/** * Returns a deep clone of this {@link AForAllExp} node. * @return a deep clone of this {@link AForAllExp} node */ public AForAllExp clone() { return new AForAllExp( _type, _location, cloneList(_bindList), cloneNode(_predicate) ); }
public static AForAllExp newAForAllExp(ILexLocation start, List<PMultipleBind> bindList, PExp predicate) { AForAllExp result = new AForAllExp(); initExpression(result, start); result.setBindList(bindList); result.setPredicate(predicate); return result; }
@Override public void caseAForAllExp(AForAllExp node) throws AnalysisException { if (!proceed(node)) { return; } handleMultipleBindConstruct(node, node.getBindList(), null, node.getPredicate()); }
@Override public LexNameSet caseAForAllExp(AForAllExp node, FreeVarInfo info) throws AnalysisException { PDefinition def = AstFactory.newAMultiBindListDefinition(node.getLocation(), node.getBindList()); FreeVarInfo local = info.set(new FlatEnvironment(af, def, info.env)); LexNameSet names = new LexNameSet(); if (node.getPredicate() != null) { names.addAll(node.getPredicate().apply(this, local)); } for (PMultipleBind mb: node.getBindList()) { names.addAll(mb.apply(this, local)); } return names; }
@Override public PExp getContextNode(PExp stitch) { try { if (first) { first = false; } PExp implies_exp = AstExpressionFactory.newAImpliesBooleanBinaryExp(pred.clone(), stitch.clone()); for (Substitution sub : subs) { implies_exp = implies_exp.clone().apply(visitor, sub); } if (forall_exp.getBindList().size() > 0) { forall_exp.setPredicate(implies_exp); return forall_exp.clone(); } else { return implies_exp.clone(); } } catch (AnalysisException e) { //consider handling of exceptions inside final context construction e.printStackTrace(); } return null; }
public POForAllContext(AForAllExp exp) { this.bindings = exp.getBindList(); }
AForAllExp forallExp = new AForAllExp(); PType leftPType = assistantFactory.createPTypeAssistant().getFunction(exp.getLeft().getType()).getParameters().get(0).clone(); forallExp.setBindList(getMultipleTypeBindList(leftPType, arg)); PExp firstPart = null; forallExp.setPredicate(secondPart); } else forallExp.setPredicate(AstExpressionFactory.newAImpliesBooleanBinaryExp(firstPart, secondPart)); stitch = forallExp.clone(); valuetree.setPredicate(ctxt.getPredWithContext(forallExp));
/** * Create the context (forall x,y,z...) for a Proof Obligation for * eq and ord relations. */ protected AForAllExp makeRelContext(ATypeDefinition node, AVariableExp... exps){ AForAllExp forall_exp = new AForAllExp(); forall_exp.setType(new ABooleanBasicType()); ATypeMultipleBind tmb = new ATypeMultipleBind(); List<PPattern> pats = new LinkedList<>(); for (AVariableExp exp : exps) { pats.add(AstFactory.newAIdentifierPattern(exp.getName().clone())); } tmb.setPlist(pats); tmb.setType(node.getType().clone()); List<PMultipleBind> binds = new LinkedList<>(); binds.add(tmb); forall_exp.setBindList(binds); return forall_exp; }
@Override public PExp caseAForAllExp(AForAllExp exp, Integer lineno) throws AnalysisException { PExp found = findExpressionBaseCase(exp, lineno); if (found != null) { return found; } return exp.getPredicate().apply(THIS, lineno);// PExpAssistantInterpreter.findExpression(exp.getPredicate(), // lineno); }
private AForAllExp getChangedVarsExp(AExplicitFunctionDefinition postDef, SOperationDefinitionBase calledOp) { AForAllExp r = new AForAllExp(); List<PMultipleBind> binds = new LinkedList<PMultipleBind>(); if (calledOp instanceof AExplicitOperationDefinition) { refreshAllState(calledOp, binds); } if (calledOp instanceof AImplicitOperationDefinition) { AImplicitOperationDefinition implicitOp = (AImplicitOperationDefinition) calledOp; if (implicitOp.getExternals().size() > 0) { for (AExternalClause external : implicitOp.getExternals()) { if (external.getMode().getType().equals(VDMToken.WRITE)) { binds.addAll(introduceFreshVars(external.getIdentifiers(), getStateVars(calledOp))); } } } else { refreshAllState(calledOp, binds); } } r.setBindList(binds); return r; }
@Override public PExp getContextNode(PExp stitch) { AForAllExp super_exp = super.getSuperContext(stitch); if (predicate != null) { AImpliesBooleanBinaryExp implies_exp = AstExpressionFactory.newAImpliesBooleanBinaryExp(predicate.clone(), stitch); implies_exp.setType(new ABooleanBasicType()); super_exp.setPredicate(implies_exp); } else { super_exp.setPredicate(stitch); } return super_exp; }
/** * Essentially this.toString().equals(o.toString()). **/ @Override public boolean equals(Object o) { if (o != null && o instanceof AForAllExp) { return toString().equals(o.toString()); } return false; }
@Override public SExpIR caseAForAllExp(AForAllExp node, IRInfo question) throws AnalysisException { // The inheritance hierarchy of the VDM AST tree is structured such that the bindings and the predicate // must also be passed to the method that handles the forall and the exists quantifiers return question.getExpAssistant().handleQuantifier(node, node.getBindList(), node.getPredicate(), new AForAllQuantifierExpIR(), question, "forall expression"); }
throws AnalysisException BreakpointManager.getBreakpoint(node).check(node.getLocation(), ctxt); for (PMultipleBind mb : node.getBindList()) Context evalContext = new Context(ctxt.assistantFactory, node.getLocation(), "forall", ctxt); NameValuePairList nvpl = quantifiers.next(); boolean matches = true; && !node.getPredicate().apply(VdmRuntime.getExpressionEvaluator(), evalContext).boolValue(ctxt)) return VdmRuntimeError.abort(node.getLocation(), e);
/** * forall a:A, b:B & p(a,b) => exists idx in set dom m & m(idx) = { a |-> b } */ private PExp getForallExp(AMapCompMapExp exp, ILexNameToken finmap, ILexNameToken findex) { AForAllExp forallExp = new AForAllExp(); forallExp.setBindList(exp.clone().getBindings()); forallExp.setPredicate(getImpliesExpression(exp, finmap, findex)); return forallExp; }
@Override public void caseAForAllExp(AForAllExp node) throws AnalysisException { validateQuantifiedExp(node, node.getBindList(), "forall expression"); }