@Override public String caseARecordInvariantType(ARecordInvariantType type) throws AnalysisException { return type.getName().toString(); }
@Override public Integer caseARecordInvariantType(ARecordInvariantType type) throws AnalysisException { return type.getName().apply(THIS); }
@Override public int hashCode() { return type.getName().hashCode() + fieldmap.hashCode(); }
@Override public PType caseARecordInvariantType(ARecordInvariantType type, String typename) throws AnalysisException { if (type.getOpaque()) { return null; } if (typename.indexOf('`') > 0) { return type.getName().getFullName().equals(typename) ? type : null; } else { // Local typenames aren't qualified with the local module name return type.getName().getName().equals(typename) ? type : null; } }
@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(); }
Record cgRecord = (Record) cgValue; if (!cgRecord.getClass().getName().endsWith(vdmRecord.type.getName().getName()))
@Override public Boolean defaultSInvariantType(SInvariantType type, Object other) throws AnalysisException { if (type instanceof ANamedInvariantType) { other = deBracket((PType) other); if (other instanceof ANamedInvariantType) { ANamedInvariantType nother = (ANamedInvariantType) other; return ((ANamedInvariantType) type).getName().equals(nother.getName()); } return false; } else if (type instanceof ARecordInvariantType) { other = af.createPTypeAssistant().deBracket(other); if (other instanceof ARecordInvariantType) { ARecordInvariantType rother = (ARecordInvariantType) other; return ((ARecordInvariantType) type).getName().equals(rother.getName()); // NB. identical } return false; } else { other = deBracket((PType) other); return type.getClass() == other.getClass(); } }
@Override public LexNameSet caseARecordInvariantType(ARecordInvariantType node, FreeVarInfo info) throws AnalysisException { if (info.env.findType(node.getName(), node.getLocation().getModule()) == null) { // Invariant values covered in TCTypeDefinition return new LexNameSet(node.getName().getExplicit(true)); } else { return new LexNameSet(); } }
String recName = ((ARecordInvariantType) type).getName().getName();
@Override public String defaultSInvariantType(SInvariantType node, PrettyPrinterEnv question) throws AnalysisException { ILexNameToken name = null; if (node instanceof ANamedInvariantType) { name = ((ANamedInvariantType) node).getName(); } else if (node instanceof ARecordInvariantType) { name = ((ARecordInvariantType) node).getName(); } if (name != null) { if (name.getModule() != null && !name.getModule().equals(question.getClassName())) { return name.getModule() + "`" + name.getFullName(); } return name.getFullName(); } return "unresolved"; }
public void checkInvariant(Context ctxt) throws AnalysisException { if (invariant != null && Settings.invchecks) { // In VDM++ and VDM-RT, we do not want to do thread swaps half way // through an invariant check, so we set the atomic flag around the // conversion. This also stops VDM-RT from performing "time step" // calculations. try { ctxt.threadState.setAtomic(true); boolean inv = invariant.eval(invariant.location, this, ctxt).boolValue(ctxt); if (!inv) { abort(4079, "Type invariant violated by mk_" + type.getName()+ " arguments", ctxt); } } finally { ctxt.threadState.setAtomic(false); } } }
@Override public STypeIR caseARecordInvariantType(ARecordInvariantType node, IRInfo question) throws AnalysisException { ILexNameToken name = node.getName(); ARecordTypeIR recordType = new ARecordTypeIR(); ATypeNameIR typeName = new ATypeNameIR(); typeName.setName(name.getName()); typeName.setDefiningClass(name.getModule()); recordType.setName(typeName); return recordType; }
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); }
PType using = af.createPTypeAssistant().isType(question.ptype, pattype.getName().getFullName());
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 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; }
return new BooleanValue(rv.type.getName().equals(node.getTypeName()));
node.getComposeDefinitions().add(AstFactory.newATypeDefinition(rtype.getName(), rtype, null, null));
canBeExecuted = rt.getName().getName().equals(node.getState().getName().getName());