Ejemplo n.º 1
0
/*
 * Print the function terms in array a
 * - n = size of the array
 */
static void eval_pp_function_assignments(yices_pp_t *printer, evaluator_t *eval, term_t *a, uint32_t n) {
  model_t *model;
  term_table_t *terms;
  value_fun_t *fun;
  char *name;
  term_t t;
  value_t c;
  uint32_t i;

  model = eval->model;
  terms = model->terms;

  // first pass: function objects
  for (i=0; i<n; i++) {
    t = a[i];
    if (is_function_term(terms, t)) {
      /*
       * t is mapped to a function object fun if t and fun have
       * different names, we print (= <t's name> <fun 's name>)
       * otherwise we print nothing and store fun in the vtbl's queue
       * (fun's map definition will be printed later).
       */
      c = eval_in_model(eval, t);
      name = term_name(terms, t);
      assert(name != NULL);
      if (object_is_function(&model->vtbl, c)) {
        fun = vtbl_function(&model->vtbl, c);
        if (fun->name == NULL || strcmp(name, fun->name) != 0) {
          pp_open_block(printer, PP_OPEN_EQ);
          pp_string(printer, name);
          vtbl_pp_object(printer, &model->vtbl, c);
          pp_close_block(printer, true);
        } else {
	  vtbl_push_object(&model->vtbl, c);
        }
      }
    }
  }

  /*
   * second pass: deal with update objects
   */
  for (i=0; i<n; i++) {
    t = a[i];
    if (is_function_term(terms, t)) {
      c = eval_in_model(eval, t);
      name = term_name(terms, t);
      assert(name != NULL);
      if (object_is_update(&model->vtbl, c)) {
        vtbl_normalize_and_pp_update(printer, &model->vtbl, name, c, true);
      }
    }
  }
}
Ejemplo n.º 2
0
/*
 * Print the function terms in array a
 * - n = size of the array
 */
static void eval_print_function_assignments(FILE *f, evaluator_t *eval, term_t *a, uint32_t n) {
  model_t *model;
  term_table_t *terms;
  value_fun_t *fun;
  char *name;
  term_t t;
  value_t c;
  uint32_t i;

  model = eval->model;
  terms = model->terms;

  // first pass: function objects
  for (i=0; i<n; i++) {
    t = a[i];
    if (is_function_term(terms, t)) {
      /*
       * t is mapped to a function object fun
       * if t and fun have different names, we print
       * (= <t's name> <fun 's name>) otherwise we print nothing
       * and store fun in the vtbl's internal queue
       */
      c = eval_in_model(eval, t);
      name = term_name(terms, t);
      assert(name != NULL);
      if (object_is_function(&model->vtbl, c)) {
        fun = vtbl_function(&model->vtbl, c);
        if (fun->name == NULL || strcmp(name, fun->name) != 0) {
          fprintf(f, "(= %s ", name);
          vtbl_print_object(f, &model->vtbl, c);
          fputs(")\n", f);
        } else {
	  vtbl_push_object(&model->vtbl, c);
        }
      }
    }
  }

  /*
   * second pass: deal with update objects
   */
  for (i=0; i<n; i++) {
    t = a[i];
    if (is_function_term(terms, t)) {
      c = eval_in_model(eval, t);
      name = term_name(terms, t);
      assert(name != NULL);
      if (object_is_update(&model->vtbl, c)) {
        vtbl_normalize_and_print_update(f, &model->vtbl, name, c, true);
      }
    }
  }
}
Ejemplo n.º 3
0
/*
 * Print the function terms in array a
 * - n = size of the array
 */
static void model_pp_function_assignments(yices_pp_t *printer, model_t *model, term_t *a, uint32_t n) {
  term_table_t *terms;
  value_fun_t *fun;
  char *name;
  term_t t;
  value_t c;
  uint32_t i;

  terms = model->terms;
  for (i=0; i<n; i++) {
    t = a[i];
    if (is_function_term(terms, t)) {
      /*
       * t is mapped to a function object fun
       * if t and fun have different names, we print
       * (= <t's name> <fun 's name>) otherwise we print nothing
       * and push fun in vtbl's internal queue.
       */
      c = model_find_term_value(model, t);
      name = term_name(terms, t);
      assert(name != NULL);
      if (object_is_function(&model->vtbl, c)) {
        fun = vtbl_function(&model->vtbl, c);
        if (fun->name == NULL || strcmp(name, fun->name) != 0) {
          pp_open_block(printer, PP_OPEN_EQ);
          pp_string(printer, name);
          vtbl_pp_object(printer, &model->vtbl, c);
          pp_close_block(printer, true);
        } else {
	  vtbl_push_object(&model->vtbl, c);
        }
      }
    }
  }

  /*
   * Second pass: print the update objects
   */
  for (i=0; i<n; i++) {
    t = a[i];
    if (is_function_term(terms, t)) {
      c = model_find_term_value(model, t);
      name = term_name(terms, t);
      assert(name != NULL);
      if (object_is_update(&model->vtbl, c)) {
        vtbl_normalize_and_pp_update(printer, &model->vtbl, name, c, true);
      }
    }
  }

}
Ejemplo n.º 4
0
/*
 * Print the function terms in array a
 * - n = size of the array
 */
static void model_print_function_assignments(FILE *f, model_t *model, term_t *a, uint32_t n) {
  term_table_t *terms;
  value_fun_t *fun;
  char *name;
  term_t t;
  value_t c;
  uint32_t i;

  terms = model->terms;
  for (i=0; i<n; i++) {
    t = a[i];
    if (is_function_term(terms, t)) {
      /*
       * t is mapped to a function object fun
       * if t and fun have different names, we print
       * (= <t's name> <fun 's name>) otherwise we print nothing
       * and push fun in value_table's queue
       */
      c = model_find_term_value(model, t);
      name = term_name(terms, t);
      assert(name != NULL);
      if (object_is_function(&model->vtbl, c)) {
        fun = vtbl_function(&model->vtbl, c);
        if (fun->name == NULL || strcmp(name, fun->name) != 0) {
          fprintf(f, "(= %s ", name);
          vtbl_print_object(f, &model->vtbl, c);
          fputs(")\n", f);
        } else {
	  vtbl_push_object(&model->vtbl, c);
        }
      }
    }
  }

  /*
   * Second pass: print the update objects
   */
  for (i=0; i<n; i++) {
    t = a[i];
    if (is_function_term(terms, t)) {
      c = model_find_term_value(model, t);
      name = term_name(terms, t);
      assert(name != NULL);
      if (object_is_update(&model->vtbl, c)) {
        vtbl_normalize_and_print_update(f, &model->vtbl, name, c, true);
      }
    }
  }
}
Ejemplo n.º 5
0
/*
 * Expand function f
 */
void yval_expand_function(value_table_t *tbl, value_t f, yval_vector_t *v, yval_t *def) {
  value_fun_t *fun;
  uint32_t i, n;
  value_t x;

  reset_yval_vector(v);

  fun = vtbl_function(tbl, f);
  get_yval(tbl, fun->def, def);
  n = fun->map_size;
  for (i=0; i<n; i++) {
    x = fun->map[i];
    assert(object_is_map(tbl, x));
    yval_vector_push(v, x, YVAL_MAPPING);
  }
}
Ejemplo n.º 6
0
/*
 * Store the mapping t := v in model
 * - t must not be mapped to anything
 * - v must be a valid object created in model->vtbl.
 *
 * If v is a function object and it has no name, then t's name is
 * given to v.
 */
void model_map_term(model_t *model, term_t t, value_t v) {
  int_hmap_pair_t *r;
  value_table_t *vtbl;
  char *name;

  assert(good_term(model->terms, t));

  r = int_hmap_get(&model->map, t);
  assert(r->val < 0);
  r->val = v;

  // copy t's name if any
  name = term_name(model->terms, t);
  if (name != NULL) {
    vtbl = &model->vtbl;
    if (object_is_function(vtbl, v) && vtbl_function(vtbl, v)->name == NULL) {
      vtbl_set_function_name(vtbl, v, name);
    }
  }
}