@Override public String caseANamedInvariantType(ANamedInvariantType type) throws AnalysisException { return type.getName().toString(); }
@Override public Integer caseANamedInvariantType(ANamedInvariantType type) throws AnalysisException { return type.getName().apply(THIS); }
@Override public Boolean caseAUnresolvedType(AUnresolvedType type, Object other) throws AnalysisException { other = deBracket((PType) other); if (other instanceof AUnresolvedType) { AUnresolvedType nother = (AUnresolvedType) other; return type.getName().equals(nother.getName()); } if (other instanceof ANamedInvariantType) { ANamedInvariantType nother = (ANamedInvariantType) other; return type.getName().equals(nother.getName()); } return false; }
@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 caseANamedInvariantType(ANamedInvariantType 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(); } }
@Override public SDeclIR caseANamedInvariantType(ANamedInvariantType node, IRInfo question) throws AnalysisException { PType type = node.getType(); STypeIR typeCg = type.apply(question.getTypeVisitor(), question); ATypeNameIR typeName = new ATypeNameIR(); typeName.setDefiningClass(node.getName().getModule()); typeName.setName(node.getName().getName()); ANamedTypeDeclIR namedTypeDecl = new ANamedTypeDeclIR(); namedTypeDecl.setName(typeName); namedTypeDecl.setType(typeCg); return namedTypeDecl; }
@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"; }
@Override public STypeIR caseANamedInvariantType(ANamedInvariantType node, IRInfo question) throws AnalysisException { PType type = node.getType(); STypeIR underlyingType = type.apply(question.getTypeVisitor(), question); // TODO: Morten initially requested some way of knowing whether a type originates // from a named invariant type. With the NamedInvTypeInfo being introduced, using // IR tags for this is redundant. Check if the IR tagging can be removed. underlyingType.setTag(new IRNamedTypeInvariantTag(node.getName().getName())); ATypeNameIR typeName = new ATypeNameIR(); typeName.setDefiningClass(node.getName().getModule()); typeName.setName(node.getName().getName()); ANamedTypeDeclIR typeDecl = new ANamedTypeDeclIR(); typeDecl.setName(typeName); if (underlyingType != null) { typeDecl.setType(underlyingType.clone()); } underlyingType.setNamedInvType(typeDecl); return underlyingType; }
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 a DTC check (which can include calculating an invariant), // so we set the atomic flag around the conversion. This also stops // VDM-RT from performing "time step" calculations. boolean inv = false; try { ctxt.threadState.setAtomic(true); inv = invariant.eval(invariant.location, value, ctxt).boolValue(ctxt); } catch (ValueException e) { throw new ContextException(4060, e.getMessage(), invariant.location, ctxt); } finally { ctxt.threadState.setAtomic(false); } if (!inv) { abort(4060, "Type invariant violated for " + type.getName(), ctxt); } } }
SInvariantType copy = AstFactory.newANamedInvariantType(ntype.getName().clone(), ntype.getType());