Esempio n. 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;
 }
Esempio n. 2
0
 /**
  * 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);
   }
 }
Esempio n. 3
0
  /**
   * Initializes the variable lists and generates the respective Alloy declarations.
   *
   * @throws EchoError
   * @todo Support fom <code>CollectionTemplateExp</code>
   */
  private void initVariableLists() throws EchoError {
    Map<EVariable, String> whenvar2model = new HashMap<EVariable, String>();
    Map<EVariable, String> sourcevar2model = new HashMap<EVariable, String>();
    Map<EVariable, String> targetvar2model = new HashMap<EVariable, String>();

    for (EModelDomain dom : relation.getDomains()) {
      rootvariables.put(dom.getRootVariable(), dom.getModel().getName());
      if (dependency.target.equals(dom)) targetdomain = dom;
      else sourcedomains.add(dom);
    }

    ECondition preCondition = relation.getPre();
    if (preCondition != null) whenvar2model = preCondition.getVariables(null);

    for (EModelDomain dom : sourcedomains) {
      ECondition cond = dom.getCondition();
      sourcevar2model.putAll(cond.getVariables(dom.getModel().getName()));
    }

    for (EVariable x : whenvar2model.keySet()) {
      whenvar2model.put(x, sourcevar2model.get(x));
      sourcevar2model.remove(x);
    }

    ECondition temp = targetdomain.getCondition();
    targetvar2model = temp.getVariables(targetdomain.getModel().getName());

    ECondition postCondition = relation.getPost();
    if (postCondition != null)
      for (EVariable x : postCondition.getVariables(null).keySet())
        if (targetvar2model.get(x) == null) targetvar2model.put(x, null);

    for (EVariable x : sourcevar2model.keySet()) {
      if (sourcevar2model.get(x) == null) sourcevar2model.put(x, targetvar2model.get(x));
      targetvar2model.remove(x);
    }

    for (EVariable x : whenvar2model.keySet()) {
      if (whenvar2model.get(x) == null) whenvar2model.put(x, targetvar2model.get(x));
      targetvar2model.remove(x);
    }

    if (!top)
      for (EVariable x : rootvariables.keySet()) {
        whenvar2model.remove(x);
        targetvar2model.remove(x);
        sourcevar2model.remove(x);
      }

    for (EVariable s : sourcevar2model.keySet()) var2model.put(s.getName(), sourcevar2model.get(s));
    for (EVariable s : targetvar2model.keySet()) var2model.put(s.getName(), targetvar2model.get(s));
    for (EVariable s : whenvar2model.keySet()) var2model.put(s.getName(), whenvar2model.get(s));
    if (!top)
      for (EVariable s : rootvariables.keySet()) var2model.put(s.getName(), rootvariables.get(s));

    sourcevar2alloydecl =
        AlloyUtil.variableListToExpr(sourcevar2model.keySet(), var2varmodel(), modelparam2var);
    for (String s : sourcevar2alloydecl.keySet()) var2var.put(s, sourcevar2alloydecl.get(s).get());
    targetvar2alloydecl =
        AlloyUtil.variableListToExpr(targetvar2model.keySet(), var2varmodel(), modelparam2var);
    for (String s : targetvar2alloydecl.keySet()) var2var.put(s, targetvar2alloydecl.get(s).get());
    whenvar2alloydecl =
        AlloyUtil.variableListToExpr(whenvar2model.keySet(), var2varmodel(), modelparam2var);
    for (String s : whenvar2alloydecl.keySet()) var2var.put(s, whenvar2alloydecl.get(s).get());
    rootvar2alloydecl =
        AlloyUtil.variableListToExpr(rootvariables.keySet(), var2varmodel(), modelparam2var);
    if (!top)
      for (String s : rootvar2alloydecl.keySet()) var2var.put(s, rootvar2alloydecl.get(s).get());
  }