@Override public void caseASetCompSetExp(ASetCompSetExp node) throws AnalysisException { if (!proceed(node)) { return; } handleMultipleBindConstruct(node, node.getBindings(), node.getFirst(), node.getPredicate()); }
public static ASetCompSetExp newASetCompSetExp(ILexLocation start, PExp first, List<PMultipleBind> bindings, PExp predicate) { ASetCompSetExp result = new ASetCompSetExp(); initExpression(result, start); result.setFirst(first); result.setBindings(bindings); result.setPredicate(predicate); return result; }
/** * Creates a new tree field only constructor {@code ASetCompSetExp TAG=setComp} 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 first_ the {@link PExp} node for the {@code first} child of this {@link ASetCompSetExp} node * @param bindings_ the {@link NodeList} node for the {@code bindings} child of this {@link ASetCompSetExp} node * @param predicate_ the {@link PExp} node for the {@code predicate} child of this {@link ASetCompSetExp} node */ public ASetCompSetExp(ILexLocation location_, PExp first_, List<? extends PMultipleBind> bindings_, PExp predicate_) { super(null,location_,null); this.setFirst(first_); this.setBindings(bindings_); this.setPredicate(predicate_); }
/** * Returns a deep clone of this {@link ASetCompSetExp} node. * @return a deep clone of this {@link ASetCompSetExp} node */ public ASetCompSetExp clone() { return new ASetCompSetExp( _type, _location, _setType, cloneNode(_first), cloneList(_bindings), cloneNode(_predicate) ); }
inASetCompSetExp(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) node.getType().apply(this); if(node.getSetType() != null && !_visitedNodes.contains(node.getSetType())) node.getSetType().apply(this); if(node.getFirst() != null && !_visitedNodes.contains(node.getFirst())) node.getFirst().apply(this); List<PMultipleBind> copy = new ArrayList<PMultipleBind>(node.getBindings()); for( PMultipleBind e : copy) if(node.getPredicate() != null && !_visitedNodes.contains(node.getPredicate())) node.getPredicate().apply(this);
@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; }
throws AnalysisException BreakpointManager.getBreakpoint(node).check(node.getLocation(), ctxt); ValueSet set = new ValueSet(); for (PMultipleBind mb : node.getBindings()) Context evalContext = new Context(ctxt.assistantFactory, node.getLocation(), "set comprehension", ctxt); NameValuePairList nvpl = quantifiers.next(); boolean matches = true; && (node.getPredicate() == null || node.getPredicate().apply(VdmRuntime.getExpressionEvaluator(), evalContext).boolValue(ctxt))) set.add(node.getFirst().apply(VdmRuntime.getExpressionEvaluator(), evalContext)); return VdmRuntimeError.abort(node.getLocation(), e);
@Override public LexNameSet caseASetCompSetExp(ASetCompSetExp node, FreeVarInfo info) throws AnalysisException { PDefinition def = AstFactory.newAMultiBindListDefinition(node.getLocation(), node.getBindings()); 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.getBindings()) { names.addAll(mb.apply(this, local)); } return names; }
@Override public PExp caseASetCompSetExp(ASetCompSetExp exp, Integer lineno) throws AnalysisException { PExp found = findExpressionBaseCase(exp, lineno); if (found != null) { return found; } found = exp.getFirst().apply(THIS, lineno); if (found != null) { return found; } return exp.getPredicate() == null ? null : exp.getPredicate().apply(THIS, lineno); }
public POForAllContext(ASetCompSetExp exp) { this.bindings = exp.getBindings(); }
/** * forall a:A & p(a) => exists idx in set dom m & m(idx) = f(a) */ private PExp getForallExp(ASetCompSetExp exp, ILexNameToken finmap, ILexNameToken findex) { AForAllExp forallExp = new AForAllExp(); forallExp.setBindList(exp.clone().getBindings()); forallExp.setPredicate(getImpliesExpression(exp, finmap, findex)); return forallExp; }
/** * p(a,b) => exists idx in set dom m & m(idx) = f(a) */ private PExp getImpliesExpression(ASetCompSetExp exp, ILexNameToken finmap, ILexNameToken findex) { if (exp.getPredicate() == null) // set comprehension has no predicate { return getImpliesExists(exp, finmap, findex); } else { return AstExpressionFactory.newAImpliesBooleanBinaryExp(exp.getPredicate().clone(), getImpliesExists(exp.clone(), finmap, findex)); } }
public POForAllPredicateContext(ASetCompSetExp exp) { super(exp); this.predicate = exp.getPredicate(); }
/** * m(idx) = f(a) */ private PExp getExistsPredicate(ASetCompSetExp exp, ILexNameToken finmap, ILexNameToken findex) { AApplyExp apply = getApplyExp(getVarExp(finmap), getVarExp(findex)); return getEqualsExp(apply, exp.getFirst()); }
throws AnalysisException super(exp, POType.FINITE_SET, ctxt, exp.getLocation(), af); existsExp.setPredicate(getForallExp(exp.clone(), finmap, findex));
inASetCompSetExp(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) node.getType().apply(this); if(node.getSetType() != null && !_visitedNodes.contains(node.getSetType())) node.getSetType().apply(this); if(node.getFirst() != null && !_visitedNodes.contains(node.getFirst())) node.getFirst().apply(this); List<PMultipleBind> copy = new ArrayList<PMultipleBind>(node.getBindings()); for( PMultipleBind e : copy) if(node.getPredicate() != null && !_visitedNodes.contains(node.getPredicate())) node.getPredicate().apply(this);
@Override public void caseASetCompSetExp(ASetCompSetExp node) throws AnalysisException { if (inUnsupportedContext(node)) { info.addUnsupportedNode(node, "Generation of a set comprehension is only supported within operations/functions"); } for (PMultipleBind mb : node.getBindings()) { mb.apply(this); } }
/** * Creates a new complete constructor {@code ASetCompSetExp} 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 first_ the {@link PExp} node for the {@code first} child of this {@link ASetCompSetExp} node * @param bindings_ the {@link NodeList} node for the {@code bindings} child of this {@link ASetCompSetExp} node * @param predicate_ the {@link PExp} node for the {@code predicate} child of this {@link ASetCompSetExp} node */ public ASetCompSetExp(PType type_, ILexLocation location_, SSetType setType_, PExp first_, List<? extends PMultipleBind> bindings_, PExp predicate_) { super(type_,location_,setType_); this.setFirst(first_); this.setBindings(bindings_); this.setPredicate(predicate_); }
/** * Creates a deep clone of this {@link ASetCompSetExp} 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 ASetCompSetExp} node */ public ASetCompSetExp clone(Map<INode,INode> oldToNewMap) { ASetCompSetExp node = new ASetCompSetExp( _type, _location, _setType, cloneNode(_first, oldToNewMap), cloneList(_bindings, oldToNewMap), cloneNode(_predicate, oldToNewMap) ); oldToNewMap.put(this, node); return node; }
inASetCompSetExp(node, question); if(node.getType() != null && !_visitedNodes.contains(node.getType())) node.getType().apply(this, question); if(node.getSetType() != null && !_visitedNodes.contains(node.getSetType())) node.getSetType().apply(this, question); if(node.getFirst() != null && !_visitedNodes.contains(node.getFirst())) node.getFirst().apply(this, question); List<PMultipleBind> copy = new ArrayList<PMultipleBind>(node.getBindings()); for( PMultipleBind e : copy) if(node.getPredicate() != null && !_visitedNodes.contains(node.getPredicate())) node.getPredicate().apply(this, question);