/** * adds to the transformation translator the constraint defining the field of this sub relation * * @param fact the constraint defining this relation * @param field the field representing this sub relation * @throws EchoError */ private void addRelationDef(Expr fact, Field field) throws EchoError { Decl fst = rootvar2alloydecl.get(relation.getDomains().get(0).getRootVariable().getName()); Decl snd = rootvar2alloydecl.get(relation.getDomains().get(1).getRootVariable().getName()); Func f; try { Expr e = field.equal(fact.comprehensionOver(fst, snd)); f = new Func(null, field.label + "def", model_params_decls, null, e); transformation_translator.addSubRelationDef(f); } catch (Err a) { throw new ErrorAlloy( ErrorAlloy.FAIL_CREATE_FUNC, "Failed to create sub relation field constraint: " + relation.getName(), a, Task.TRANSLATE_TRANSFORMATION); } }
/** * adds to the transformation translator the constraint defining this top relation * * @param fact the constraint defining this relation * @throws EchoError */ private void addRelationPred(Expr fact) throws EchoError { try { transformation_translator.addTopRelationCall( new Func( null, AlloyUtil.relationPredName(relation, dependency.target), model_params_decls, null, fact)); } catch (Err a) { throw new ErrorAlloy( ErrorAlloy.FAIL_CREATE_FUNC, "Failed to create top relation constraint function: " + relation.getName(), a, Task.TRANSLATE_TRANSFORMATION); } }
/** * adds to the transformation translator the field representing this sub relation * * @throws EchoError */ private Field addRelationField() throws EchoError { Field field = null; try { field = addRelationFields(); transformation_translator.addSubRelationCall( new Func( null, AlloyUtil.relationFieldName(relation, dependency.target), model_params_decls, field.type().toExpr(), field)); } catch (Err a) { throw new ErrorAlloy( ErrorAlloy.FAIL_CREATE_FUNC, "Failed to create sub relation constraint function: " + relation.getName(), a, Task.TRANSLATE_TRANSFORMATION); } return field; }