public AFieldField findField(ARecordInvariantType rec, String tag) { for (AFieldField f : rec.getFields()) { if (f.getTag().equals(tag)) { return f; } } return null; }
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; }
@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(); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("mk_" + type.getName() + "("); Iterator<AFieldField> fi = type.getFields().iterator(); if (fi.hasNext()) { String ftag = fi.next().getTag(); sb.append(fieldmap.get(ftag)); while (fi.hasNext()) { ftag = fi.next().getTag(); sb.append(", " + fieldmap.get(ftag)); } } sb.append(")"); return sb.toString(); }
@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 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; }
@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()); } }
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); }
@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(); } } }
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); }
List<AFieldField> copy = new ArrayList<AFieldField>(node.getFields()); for( AFieldField e : copy)
List<AFieldField> copy = new ArrayList<AFieldField>(node.getFields()); for( AFieldField e : copy)
List<AFieldField> copy = new ArrayList<AFieldField>(node.getFields()); for( AFieldField e : copy)
for (AFieldField field : type.getFields())
List<AFieldField> copy = new ArrayList<AFieldField>(node.getFields()); for( AFieldField e : copy)
@Override public SDeclIR caseARecordInvariantType(ARecordInvariantType node, IRInfo question) throws AnalysisException { ILexNameToken name = node.getName(); LinkedList<AFieldField> fields = node.getFields(); ARecordDeclIR record = new ARecordDeclIR(); record.setName(name.getName()); if (node.getInvDef() != null && question.getSettings().generateInvariants()) { SDeclIR invCg = node.getInvDef().apply(question.getDeclVisitor(), question); record.setInvariant(invCg); } LinkedList<AFieldDeclIR> recordFields = record.getFields(); for (AFieldField aFieldField : fields) { SDeclIR res = aFieldField.apply(question.getDeclVisitor(), question); if (res instanceof AFieldDeclIR) { AFieldDeclIR fieldDecl = (AFieldDeclIR) res; recordFields.add(fieldDecl); } else { return null; } } return record; }
for (AFieldField f : recordType.getFields())
for (AFieldField f : type.getFields())
for (AFieldField field : rtype.getFields())