Example #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));
  }
Example #2
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;
  }
Example #3
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;
 }
Example #4
0
  private static boolean assignmentsSound(Node node) {
    Set<String> toAssign = new HashSet<>();
    toAssign.addAll(Util.getIds(node.outputs));
    toAssign.addAll(Util.getIds(node.locals));
    Set<String> assigned = new HashSet<>();
    boolean sound = true;

    for (Equation eq : node.equations) {
      for (IdExpr idExpr : eq.lhs) {
        if (toAssign.contains(idExpr.id)) {
          toAssign.remove(idExpr.id);
          assigned.add(idExpr.id);
        } else if (assigned.contains(idExpr.id)) {
          System.out.println(
              "Error at line "
                  + idExpr.location
                  + " variable '"
                  + idExpr.id
                  + "' cannot be reassigned");
          sound = false;
        } else {
          System.out.println(
              "Error at line "
                  + idExpr.location
                  + " variable '"
                  + idExpr.id
                  + "' cannot be assigned");
          sound = false;
        }
      }
    }

    if (!toAssign.isEmpty()) {
      System.out.println("Error in node '" + node.id + "' variables must be assigned: " + toAssign);
      sound = false;
    }

    return sound;
  }
Example #5
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;
 }