/** * 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); }
@Override public String caseATypeDefinition(ATypeDefinition node, PrettyPrinterEnv question) throws AnalysisException { StringBuilder sb = new StringBuilder(question.getIdent()); sb.append(node.getAccess().getAccess() + " "); sb.append(node.getName()); if (node.getType() instanceof ARecordInvariantType) { ARecordInvariantType record = (ARecordInvariantType) node.getType(); sb.append(" :: "); for (Iterator<AFieldField> itr = record.getFields().iterator(); itr.hasNext();) { if (itr.hasNext()) { sb.append("\n" + question.getIdent()); } sb.append(itr.next().apply(this, question)); } } else { sb.append(" = " + node.getType().apply(typePrinter, question)); } // + (node.getType() instanceof ARecordInvariantType ? " :: " // : " = ") + node.getType().apply(typePrinter, question)); return sb.toString() + ";"; }
@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(); }
public static AFieldField newAFieldField(ILexNameToken tagname, String tag, PType type, boolean equalityAbstraction) { AFieldField result = new AFieldField(); result.setAccess(null); result.setTagname(tagname); result.setTag(tag); result.setType(type); result.setEqualityAbstraction(equalityAbstraction); return result; }
@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(); }
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; }
@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; }
Value sv = context.get(f.getTagname()); sv.set(ee.getLocation(), iv.fieldmap.get(f.getTag()), globals);
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); }
@Override public Boolean caseAFieldField(AFieldField node) throws AnalysisException { if (!(isNotNull(node.getTagname()) && isNotNull(node.getTagname().getName()))) { invalidNodes.add(node); return false; } return true; }
@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); } }
public AFieldField findField(ARecordInvariantType rec, String tag) { for (AFieldField f : rec.getFields()) { if (f.getTag().equals(tag)) { return f; } } return null; }
if (!f.getEqualityAbstraction()) Value fv = fieldmap.get(f.getTag()); Value ofv = ot.fieldmap.get(f.getTag());
@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()); } }
ctxt.put(field.getTagname(), sigma.fieldmap.get(field.getTag()));
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); }
private List<PDefinition> findFieldDefs(List<PDefinition> stateDefs, List<AFieldField> fields) { List<PDefinition> fieldDefs = new LinkedList<PDefinition>(); for (PDefinition d : stateDefs) { for (AFieldField f : fields) { if (f.getTagname().equals(d.getName())) { fieldDefs.add(d); break; } } } return fieldDefs; }
private static AFieldField findField(ARecordInvariantType ty, ILexIdentifierToken id) { List<AFieldField> fields = ty.getFields(); for (AFieldField f : fields) { if (f.getTag().equals(id.getName())) { return f; } } return null; }
/** * Creates a new complete constructor {@code AFieldField} 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 access_ the {@link AAccessSpecifierAccessSpecifier} node for the {@code access} child of this {@link AFieldField} node * @param tagname_ the {@link ILexNameToken} node for the {@code tagname} child of this {@link AFieldField} node * @param tag_ the {@link String} node for the {@code tag} child of this {@link AFieldField} node * @param type_ the {@link PType} <b>graph</a> node for the {@code type} child of this {@link AFieldField} node. * <i>The parent of this {@code type } will not be changed by adding it to this node.</i> * @param equalityAbstraction_ the {@link Boolean} node for the {@code equalityAbstraction} child of this {@link AFieldField} node */ public AFieldField(AAccessSpecifierAccessSpecifier access_, ILexNameToken tagname_, String tag_, PType type_, Boolean equalityAbstraction_) { super(); this.setAccess(access_); this.setTagname(tagname_); this.setTag(tag_); this.setType(type_); this.setEqualityAbstraction(equalityAbstraction_); }