Beispiel #1
0
 /**
  * Generates the relation field over the model sigs for called relations Must be run before the
  * relation constraint is created (otherwise recursive calls will fail)
  *
  * @return the Alloy field for this relation
  * @throws EchoError
  * @todo Support for n models
  */
 private Field addRelationFields() throws EchoError {
   Field field = null;
   Decl fst = rootvar2alloydecl.get(relation.getDomains().get(0).getRootVariable().getName());
   /*Decl snd = rootvar2alloydecl.get(relation.getDomains().get(1)
   .getVariable().getName());*/
   try {
     Sig s = (Sig) fst.expr.type().toExpr();
     for (Field f : s.getFields()) {
       if (f.label.equals(AlloyUtil.relationFieldName(relation, dependency.target))) field = f;
     }
     if (field == null) {
       field =
           s.addField(
               AlloyUtil.relationFieldName(relation, dependency.target),
               /*type.setOf()*/ Sig.UNIV.setOf());
     }
   } catch (Err a) {
     throw new ErrorAlloy(
         ErrorAlloy.FAIL_CREATE_FIELD,
         "Failed to create relation field representation: " + relation.getName(),
         a,
         Task.TRANSLATE_TRANSFORMATION);
   }
   return field;
 }
Beispiel #2
0
 /**
  * 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;
 }