@Override public void caseAMapCompMapExp(AMapCompMapExp node) throws AnalysisException { if (!proceed(node)) { return; } handleMultipleBindConstruct(node, node.getBindings(), node.getFirst(), node.getPredicate()); }
public static AMapCompMapExp newAMapCompMapExp(ILexLocation start, AMapletExp first, List<PMultipleBind> bindings, PExp predicate) { AMapCompMapExp result = new AMapCompMapExp();// start, first, bindings, // predicate); initExpression(result, start); result.setFirst(first); result.setBindings(bindings); result.setPredicate(predicate); return result; }
/** * Returns a deep clone of this {@link AMapCompMapExp} node. * @return a deep clone of this {@link AMapCompMapExp} node */ public AMapCompMapExp clone() { return new AMapCompMapExp( _type, _location, cloneNode(_first), cloneList(_bindings), cloneNode(_predicate) ); }
inAMapCompMapExp(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) node.getType().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 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(); }
throws AnalysisException BreakpointManager.getBreakpoint(node).check(node.getLocation(), ctxt); ValueMap map = new ValueMap(); for (PMultipleBind mb : node.getBindings()) Context evalContext = new Context(ctxt.assistantFactory, node.getLocation(), "map comprehension", ctxt); NameValuePairList nvpl = quantifiers.next(); boolean matches = true; && (node.getPredicate() == null || node.getPredicate().apply(VdmRuntime.getExpressionEvaluator(), evalContext).boolValue(ctxt))) Value dom = node.getFirst().getLeft().apply(VdmRuntime.getExpressionEvaluator(), evalContext); Value rng = node.getFirst().getRight().apply(VdmRuntime.getExpressionEvaluator(), evalContext); node.getFirst().getLocation().hit(); VdmRuntimeError.abort(node.getLocation(), 4016, "Duplicate map keys have different values: " + dom, ctxt); return VdmRuntimeError.abort(node.getLocation(), e);
@Override public LexNameSet caseAMapCompMapExp(AMapCompMapExp 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(); // Note "first" is conditional if (node.getPredicate() != null) { node.getPredicate().apply(this, local); } for (PMultipleBind mb: node.getBindings()) { names.addAll(mb.apply(this, local)); } return names; }
@Override public PExp caseAMapCompMapExp(AMapCompMapExp 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(AMapCompMapExp exp) { this.bindings = exp.getBindings(); }
/** * 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; }
public POForAllPredicateContext(AMapCompMapExp exp) { super(exp); this.predicate = exp.getPredicate(); }
public MapInjectivityComp(AMapCompMapExp exp, IPOContextStack ctxt, IPogAssistantFactory af) throws AnalysisException { super(exp, POType.MAP_INJ_COMP, ctxt, exp.getLocation(), af); stitch = buildPredicate(exp.clone()); valuetree.setPredicate(ctxt.getPredWithContext(stitch)); }
/** * m(idx) = { a |-> b } */ private PExp getExistsPredicate(AMapCompMapExp exp, ILexNameToken finmap, ILexNameToken findex) { AApplyExp apply = getApplyExp(getVarExp(finmap), getVarExp(findex)); AMapEnumMapExp setEnum = new AMapEnumMapExp(); List<AMapletExp> members = new Vector<AMapletExp>(); members.add(exp.getFirst().clone()); setEnum.setMembers(members); return getEqualsExp(apply, setEnum); } }
inAMapCompMapExp(node, question); if(node.getType() != null && !_visitedNodes.contains(node.getType())) node.getType().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);
@Override public void caseAMapCompMapExp(AMapCompMapExp node) throws AnalysisException { if (inUnsupportedContext(node)) { info.addUnsupportedNode(node, "Generation of a map comprehension is only supported within operations/functions"); } for (PMultipleBind mb : node.getBindings()) { mb.apply(this); } }
/** * p(a,b) => exists idx in set dom m & m(idx) = { a |-> b } */ private PExp getImpliesExpression(AMapCompMapExp exp, ILexNameToken finmap, ILexNameToken findex) { if (exp.getPredicate() == null) // Map comprehension has no predicate { return getImpliesExists(exp, finmap, findex); } else { return AstExpressionFactory.newAImpliesBooleanBinaryExp(exp.getPredicate(), getImpliesExists(exp, finmap, findex)); } }
public FiniteMapObligation(AMapCompMapExp exp, PType mapType, IPOContextStack ctxt, IPogAssistantFactory af) throws AnalysisException { super(exp, POType.FINITE_MAP, ctxt, exp.getLocation(), af); ILexNameToken finmap = getUnique("finmap"); ILexNameToken findex = getUnique("findex"); // eg. { a |-> b | a:A, b:B & p(a,b) }, gives... // // exists m:map nat to map A to B & // forall a:A, b:B & // p(a,b) => exists idx in set dom m & // m(idx) = { a |-> b } AExistsExp existsExp = new AExistsExp(); AMapMapType natmaptype = new AMapMapType(); natmaptype.setFrom(new ANatNumericBasicType()); natmaptype.setTo(mapType.clone()); existsExp.setBindList(getMultipleTypeBindList(natmaptype, finmap)); existsExp.setPredicate(getForallExp(exp.clone(), finmap, findex)); stitch = existsExp.clone(); valuetree.setPredicate(ctxt.getPredWithContext(existsExp)); }
/** * Creates a deep clone of this {@link AMapCompMapExp} 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 AMapCompMapExp} node */ public AMapCompMapExp clone(Map<INode,INode> oldToNewMap) { AMapCompMapExp node = new AMapCompMapExp( _type, _location, cloneNode(_first, oldToNewMap), cloneList(_bindings, oldToNewMap), cloneNode(_predicate, oldToNewMap) ); oldToNewMap.put(this, node); return node; }
inAMapCompMapExp(node); if(node.getType() != null && !_visitedNodes.contains(node.getType())) node.getType().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 ValueList caseAMapCompMapExp(AMapCompMapExp exp, ObjectContext ctxt) throws AnalysisException { ValueList list = exp.getFirst().apply(THIS, ctxt); for (PMultipleBind mb : exp.getBindings()) { list.addAll(ctxt.assistantFactory.createPMultipleBindAssistant().getValues(mb, ctxt)); } if (exp.getPredicate() != null) { list.addAll(exp.getPredicate().apply(THIS, ctxt)); } return list; }