@Override public PType caseAFieldField(AFieldField f, Newquestion question) throws AnalysisException { // Recursion defence done by the type f.setType(af.createPTypeAssistant().typeResolve(f.getType(), question.root, question.rootVisitor, question.question)); if (question.question.env.isVDMPP()) { if (f.getType() instanceof AFunctionType) { f.getTagname().setTypeQualifier(((AFunctionType) f.getType()).getParameters()); } else if (f.getType() instanceof AOperationType) { f.getTagname().setTypeQualifier(((AOperationType) f.getType()).getParameters()); } } return f.getType(); }
@Override public String caseAFieldField(AFieldField node, PrettyPrinterEnv question) throws AnalysisException { question.increaseIdent(); StringBuilder sb = new StringBuilder(question.getIdent()); sb.append(node.getTag() + " : " + node.getType().apply(typePrinter, question)); question.decreaseIdent(); return sb.toString(); }
@Override public String caseARecordInvariantType(ARecordInvariantType node, PrettyPrinterEnv question) throws AnalysisException { StringBuilder sb = new StringBuilder(); question.increaseIdent(); sb.append("\n"); for (AFieldField f : node.getFields()) { sb.append(question.getIdent() + f.getTag() + " : " + f.getType().apply(typePrinter, question) + "\n"); } question.decreaseIdent(); if (node.getFields().size() > 0) { sb.delete(sb.length() - 1, sb.length()); } return sb.toString(); }
private List<PMultipleBind> getInvBinds(AStateDefinition node) { List<PMultipleBind> r = new Vector<PMultipleBind>(); for (AFieldField f : node.getFields()) { r.add(getMultipleTypeBind(f.getType().clone(), f.getTagname().clone())); } return r; }
/** * Called by the {@link AFieldField} node from {@link AFieldField#apply(IAnalysis)}. * @param node the calling {@link AFieldField} node */ public void caseAFieldField(AFieldField node) throws AnalysisException { _visitedNodes.add(node); inAFieldField(node); if(node.getAccess() != null && !_visitedNodes.contains(node.getAccess())) { node.getAccess().apply(this); } if(node.getTagname() != null ) { node.getTagname().apply(this); } if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this); } outAFieldField(node); }
/** * Called by the {@link AFieldField} node from {@link AFieldField#apply(IPOFAnalysis)}. * @param node the calling {@link AFieldField} node */ public void caseAFieldField(AFieldField node) throws AnalysisException { _visitedNodes.add(node); inAFieldField(node); if(node.getAccess() != null && !_visitedNodes.contains(node.getAccess())) { node.getAccess().apply(this); } if(node.getTagname() != null ) { node.getTagname().apply(this); } if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this); } outAFieldField(node); }
/** * Called by the {@link AFieldField} node from {@link AFieldField#apply(IAnalysis)}. * @param node the calling {@link AFieldField} node */ public void caseAFieldField(AFieldField node, Q question) throws AnalysisException { _visitedNodes.add(node); inAFieldField(node, question); if(node.getAccess() != null && !_visitedNodes.contains(node.getAccess())) { node.getAccess().apply(this, question); } if(node.getTagname() != null ) { node.getTagname().apply(this, question); } if(node.getType() != null && !_visitedNodes.contains(node.getType())) { node.getType().apply(this, question); } outAFieldField(node, question); }
@Override public ValueList caseARecordInvariantType(ARecordInvariantType type, Context ctxt) throws AnalysisException { List<PType> types = new Vector<PType>(); for (AFieldField f : type.getFields()) { types.add(f.getType()); } ValueList results = new ValueList(); for (Value v : getAllValues(types, ctxt)) { try { TupleValue tuple = (TupleValue) v; results.add(new RecordValue(type, tuple.values, ctxt)); } catch (ValueException e) { // Value does not match invariant, so ignore it } } return results; }
/** * Called by the {@link AFieldField} node from {@link AFieldField#apply(IAnalysis)}. * @param node the calling {@link AFieldField} node */ public A caseAFieldField(AFieldField node, Q question) throws AnalysisException { _visitedNodes.add(node); A retVal = createNewReturnValue(node, question); mergeReturns(retVal,inAFieldField(node, question)); if(node.getAccess() != null && !_visitedNodes.contains(node.getAccess())) { mergeReturns(retVal,node.getAccess().apply(this, question)); } if(node.getTagname() != null ) { mergeReturns(retVal,node.getTagname().apply(this, question)); } if(node.getType() != null && !_visitedNodes.contains(node.getType())) { mergeReturns(retVal,node.getType().apply(this, question)); } mergeReturns(retVal,outAFieldField(node, question)); return retVal; }
/** * Called by the {@link AFieldField} node from {@link AFieldField#apply(IAnalysis)}. * @param node the calling {@link AFieldField} node */ public A caseAFieldField(AFieldField node) throws AnalysisException { _visitedNodes.add(node); A retVal = createNewReturnValue(node); mergeReturns(retVal,inAFieldField(node)); if(node.getAccess() != null && !_visitedNodes.contains(node.getAccess())) { mergeReturns(retVal,node.getAccess().apply(this)); } if(node.getTagname() != null ) { mergeReturns(retVal,node.getTagname().apply(this)); } if(node.getType() != null && !_visitedNodes.contains(node.getType())) { mergeReturns(retVal,node.getType().apply(this)); } mergeReturns(retVal,outAFieldField(node)); return retVal; }
@Override public SDeclIR caseAFieldField(AFieldField node, IRInfo question) throws AnalysisException { // Record fields are public String access = IRConstants.PUBLIC; String name = node.getTagname().getName(); boolean isStatic = false; boolean isFinal = false; STypeIR type = node.getType().apply(question.getTypeVisitor(), question); SExpIR exp = null; return question.getDeclAssistant().constructField(access, name, isStatic, isFinal, type, exp); }
@Override public void caseARecordInvariantType(ARecordInvariantType type) throws AnalysisException { if (!type.getResolved()) { return; } else { type.setResolved(false); } for (AFieldField f : type.getFields()) { af.createPTypeAssistant().unResolve(f.getType()); } }
@Override public PTypeList caseARecordInvariantType(ARecordInvariantType node) throws AnalysisException { if (node.getComposed()) { PTypeList types = new PTypeList(node); for (AFieldField f : node.getFields()) { types.addAll(f.getType().apply(THIS)); } return types; } else { return new PTypeList(); } } }
@Override // RWL See [1] pg. 56 public IProofObligationList caseAMuExp(AMuExp node, IPOContextStack question) throws AnalysisException { IProofObligationList obligations = node.getRecord().apply(rootVisitor, question); Queue<ARecordModifier> modifiers = node.getModifiers(); ARecordInvariantType recordType = node.getRecordType(); LinkedList<PType> mTypes = node.getModTypes(); int i = 0; for (ARecordModifier mod : modifiers) { obligations.addAll(mod.getValue().apply(mainVisitor, question)); AFieldField f = findField(recordType, mod.getTag()); PType mType = mTypes.get(i++); if (f != null) { if (!aF.getTypeComparator().isSubType(mType, f.getType())) { TypeCompatibilityObligation sto = TypeCompatibilityObligation.newInstance(mod.getValue(), f.getType(), mType, question, aF); if (sto != null) { obligations.add(sto); } } } } return obligations; }
public RecordValue(ARecordInvariantType type, ValueList values, Context ctxt) throws AnalysisException { this.type = type; this.fieldmap = new FieldMap(); this.invariant = ctxt.assistantFactory.createSInvariantTypeAssistant().getInvariant(type, ctxt); this.equality = ctxt.assistantFactory.createSInvariantTypeAssistant().getEquality(type, ctxt); this.ordering = ctxt.assistantFactory.createSInvariantTypeAssistant().getOrder(type, ctxt); if (values.size() != type.getFields().size()) { abort(4078, "Wrong number of fields for " + type.getName(), ctxt); } Iterator<AFieldField> fi = type.getFields().iterator(); for (Value v : values) { AFieldField f = fi.next(); fieldmap.add(f.getTag(), v.convertTo(f.getType(), ctxt), !f.getEqualityAbstraction()); } checkInvariant(ctxt); }
defs.addAll(af.createPPatternAssistant().getDefinitions(p, pf.getType(), question.scope));
public RecordValue(ARecordInvariantType type, FieldMap mapvalues, Context ctxt) throws AnalysisException { this.type = type; this.fieldmap = new FieldMap(); this.invariant = ctxt.assistantFactory.createSInvariantTypeAssistant().getInvariant(type, ctxt); this.equality = ctxt.assistantFactory.createSInvariantTypeAssistant().getEquality(type, ctxt); this.ordering = ctxt.assistantFactory.createSInvariantTypeAssistant().getOrder(type, ctxt); if (mapvalues.size() != type.getFields().size()) { abort(4080, "Wrong number of fields for " + type.getName(), ctxt); } Iterator<AFieldField> fi = type.getFields().iterator(); while (fi.hasNext()) { AFieldField f = fi.next(); Value v = mapvalues.get(f.getTag()); if (v == null) { abort(4081, "Field not defined: " + f.getTag(), ctxt); } fieldmap.add(f.getTag(), v.convertTo(f.getType(), ctxt), !f.getEqualityAbstraction()); } checkInvariant(ctxt); }
private PExp makeInvApplyExp(AAtomicStm atom) { AStateDefinition stateDef = atom.getAssignments().get(0).getStateDefinition(); if (stateDef == null) { return extractInv(atom); } String stateName = getStateName(stateDef); List<PExp> arglist = new Vector<PExp>(); for (AFieldField f : stateDef.getFields()) { arglist.add(getVarExp(f.getTagname().clone(), stateDef.clone(),f.getType())); } PExp mkExp = AstExpressionFactory.newAMkTypeExp(new LexNameToken("", stateName, null), stateDef.getRecordType().clone(), arglist); AApplyExp invApplyExp = getApplyExp(getVarExp(stateDef.getInvdef().getName().clone(), stateDef.getInvdef().clone(), stateDef.getInvdef().getType().clone()), new ABooleanBasicType(), mkExp); invApplyExp.getRoot().setType(stateDef.getInvdef().getType().clone()); return invApplyExp; }
@Override public void caseAStateDefinition(AStateDefinition node, NewQuestion question) throws AnalysisException { for (AFieldField f : node.getFields()) { try { f.apply(THIS, new NewQuestion(question.rootVisitor, question.question)); } catch (TypeCheckException e) { question.question.assistantFactory.createPTypeAssistant().unResolve(f.getType()); throw e; } } node.setRecordType(af.createPTypeAssistant().typeResolve(node.getRecordType(), null, question.rootVisitor, question.question)); if (node.getInvPattern() != null) { node.getInvdef().apply(this, question); ARecordInvariantType rtype = (ARecordInvariantType) node.getRecordType(); rtype.setInvDef(node.getInvdef()); } if (node.getInitPattern() != null) { node.getInitdef().apply(this, question); } }