Ejemplo n.º 1
0
  private static Relation constructGeneralTransitionRelation(Node node, List<String> ivc) {
    Lustre2Sexp visitor = new Lustre2Sexp(1);
    List<Sexp> conjuncts = new ArrayList<>();

    LinkedBiMap<String, Symbol> ivcMap = createIvcMap(ivc);

    for (Equation eq : node.equations) {
      Sexp body = eq.expr.accept(visitor);
      Sexp head = eq.lhs.get(0).accept(visitor);
      Sexp sexp = new Cons("=", head, body);

      String id = eq.lhs.get(0).id;
      if (ivcMap.containsKey(id)) {
        sexp = new Cons("=>", ivcMap.get(id), sexp);
      }
      conjuncts.add(sexp);
    }

    for (Expr assertion : node.assertions) {
      conjuncts.add(assertion.accept(visitor));
    }

    List<VarDecl> inputs = new ArrayList<>();
    inputs.add(new VarDecl(INIT.str, NamedType.BOOL));
    inputs.addAll(visitor.pre(Util.getVarDecls(node)));
    inputs.addAll(visitor.curr(Util.getVarDecls(node)));
    return new Relation(Relation.T, inputs, SexpUtil.conjoin(conjuncts));
  }
Ejemplo n.º 2
0
 private static Set<String> getBooleans(Node node) {
   Set<String> booleans = new HashSet<>();
   for (VarDecl varDecl : Util.getVarDecls(node)) {
     if (varDecl.type == NamedType.BOOL) {
       booleans.add(varDecl.id);
     }
   }
   return booleans;
 }
Ejemplo n.º 3
0
 private static boolean variablesUnique(Node node) {
   boolean unique = true;
   Set<String> seen = new HashSet<>();
   for (VarDecl decl : Util.getVarDecls(node)) {
     if (seen.contains(decl.id)) {
       System.out.println(
           "Error at line " + decl.location + " variable " + decl.id + " already declared");
       unique = false;
     } else {
       seen.add(decl.id);
     }
   }
   return unique;
 }
Ejemplo n.º 4
0
  private static boolean propertiesExist(Program program) {
    boolean exist = true;

    for (Node node : program.nodes) {
      Set<String> variables = new HashSet<>(Util.getIds(Util.getVarDecls(node)));
      for (String prop : node.properties) {
        if (!variables.contains(prop)) {
          System.out.println(
              "Error: property '" + prop + "' does not exist in node '" + node.id + "'");
          exist = false;
        }
      }
    }

    return exist;
  }