void list_names_that_must_be_looped(Block* contents, Value* names) { // Find all names within 'contents' that must be looped. A name must be looped when // a term inside the loop binds a name that was already used outside the loop. Value namesMap; set_hashtable(&namesMap); for (BlockIteratorFlat it(contents); it; ++it) { Term* term = it.current(); if (has_empty_name(term)) continue; Value termVal; termVal.set_term(contents->owningTerm); Term* outsideName = find_name_at(&termVal, term_name(term)); // Don't look at names outside the major block. if (outsideName != NULL && !is_under_same_major_block(term, outsideName)) outsideName = NULL; if (outsideName != NULL) set_bool(hashtable_insert(&namesMap, term_name(term)), true); } hashtable_get_keys(&namesMap, names); list_sort(names, NULL, NULL); }
/* * 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); } } } }
/* * 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); } } } }
/* * 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); } } } }
/* * 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); } } } }
/* * Print the terms of uninterpreted type in array a * - n = size of the array */ static void eval_print_constant_assignments(FILE *f, evaluator_t *eval, term_t *a, uint32_t n) { model_t *model; term_table_t *terms; char *name; value_unint_t *d; uint32_t i; term_t t; value_t c; type_kind_t tau; model = eval->model; terms = model->terms; for (i=0; i<n; i++) { t = a[i]; tau = term_type_kind(terms, t); if (tau == UNINTERPRETED_TYPE || tau == SCALAR_TYPE) { c = eval_in_model(eval, t); d = vtbl_unint(&model->vtbl, c); name = term_name(terms, t); assert(name != NULL); if (d->name == NULL || strcmp(name, d->name) != 0) { fprintf(f, "(= %s ", name); vtbl_print_object(f, &model->vtbl, c); fputs(")\n", f); } } } }
NativeFuncIndex find_native_func_index(World* world, Block* block) { if (block->owningTerm == NULL) return -1; Value* funcName = term_name(block->owningTerm); if (is_null(funcName)) return -1; Block* module = find_enclosing_module(block); if (module == NULL) return -1; Value* moduleName = block_get_property(module, s_Name); if (moduleName == NULL) return -1; NativePatch* nativePatch = find_existing_native_patch(world, moduleName); if (nativePatch == NULL) return -1; Value* patchIndex = hashtable_get(&nativePatch->funcMap, funcName); if (patchIndex == NULL) return -1; return patchIndex->asInt(); }
/* * Print the terms of uninterpreted type in array a * - n = size of the array */ static void eval_pp_constant_assignments(yices_pp_t *printer, evaluator_t *eval, term_t *a, uint32_t n) { model_t *model; term_table_t *terms; char *name; value_unint_t *d; uint32_t i; term_t t; value_t c; type_kind_t tau; model = eval->model; terms = model->terms; for (i=0; i<n; i++) { t = a[i]; tau = term_type_kind(terms, t); if (tau == UNINTERPRETED_TYPE || tau == SCALAR_TYPE) { c = eval_in_model(eval, t); d = vtbl_unint(&model->vtbl, c); name = term_name(terms, t); assert(name != NULL); if (d->name == NULL || strcmp(name, d->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); } } } }
void Term__name(VM* vm) { Term* t = as_term_ref(vm->input(0)); if (t == NULL) return vm->throw_str("NULL term"); if (has_empty_name(t)) set_string(vm->output(), ""); else copy(term_name(t), vm->output()); }
/* * Function to get the name of constant/uninterpreted terms * - we check in the term table */ static const char *name_of_const(term_table_t *terms, value_unint_t *d) { const char *s; term_t t; s = NULL; t = find_constant_term(terms, d->type, d->index); if (t != NULL_TERM) { s = term_name(terms, t); } return s; }
/* * 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); } } }
/* * Print the assignment for t as computed by the evaluator * - t must be a valid, uninterpreted term */ static void eval_print_term_value(FILE *f, evaluator_t *eval, term_t t) { model_t *model; char *name; value_t v; assert(term_kind(eval->model->terms, t) == UNINTERPRETED_TERM); model = eval->model; v = eval_in_model(eval, t); if (v >= 0) { // v = good value for t name = term_name(model->terms, t); if (name == NULL) { fprintf(f, "(= t!%"PRId32" ", t); } else { fprintf(f, "(= %s ", name); } vtbl_print_object(f, &model->vtbl, v); fputc(')', f); } }
/* * Print the assignment for t as computed by the evaluator * - t must be a valid, uninterpreted term */ static void eval_pp_term_value(yices_pp_t *printer, evaluator_t *eval, term_t t) { model_t *model; char *name; value_t v; assert(term_kind(eval->model->terms, t) == UNINTERPRETED_TERM); model = eval->model; v = eval_in_model(eval, t); if (v >= 0) { // v = good value for t pp_open_block(printer, PP_OPEN_EQ); name = term_name(model->terms, t); if (name == NULL) { pp_id(printer, "t!", t); } else { pp_string(printer, name); } vtbl_pp_object(printer, &model->vtbl, v); pp_close_block(printer, true); } }
/* * Print the assignment for i in model */ void model_pp_term_value(yices_pp_t *printer, model_t *model, term_t t) { char *name; value_t v; assert(term_kind(model->terms, t) == UNINTERPRETED_TERM); pp_open_block(printer, PP_OPEN_EQ); name = term_name(model->terms, t); if (name == NULL) { pp_id(printer, "t!", t); } else { pp_string(printer, name); } v = model_find_term_value(model, t); if (v == null_value) { pp_string(printer, "???"); } else { vtbl_pp_object(printer, &model->vtbl, v); } pp_close_block(printer, true); }
/* * Print the assignment for t in model * - the format is (= <t's name> <value>) */ void model_print_term_value(FILE *f, model_t *model, term_t t) { char *name; value_t v; assert(term_kind(model->terms, t) == UNINTERPRETED_TERM); name = term_name(model->terms, t); if (name == NULL) { fprintf(f, "(= t!%"PRId32" ", t); } else { fprintf(f, "(= %s ", name); } v = model_find_term_value(model, t); if (v == null_value) { /* * ??) is a C trigraph so "???)" can't be written as is. */ fputs("???"")", f); } else { vtbl_print_object(f, &model->vtbl, v); fputc(')', f); } }
Value* block_name(Block* block) { if (block->owningTerm == NULL) return NULL; return term_name(block->owningTerm); }
/* * Filter function for model_collect_terms * - aux is a term table * - return true if term t should be printed in the assignments (i.e., t has a name) */ static bool term_to_print(void *aux, term_t t) { return term_kind(aux, t) == UNINTERPRETED_TERM && term_name(aux, t) != NULL; }