void PassImpl::compute_analysis_stats(const WholeProgramState& wps) { if (!wps.get_field_partition().is_top()) { for (auto& pair : wps.get_field_partition().bindings()) { auto* field = pair.first; auto& value = pair.second; if (value.is_top()) { continue; } // Since a boolean value can only have 1 and 0 as values, "GEZ" tells us // nothing useful about this field. if (is_boolean(field->get_type()) && value.equals(SignedConstantDomain(sign_domain::Interval::GEZ))) { continue; } ++m_stats.constant_fields; } } if (!wps.get_method_partition().is_top()) { for (auto& pair : wps.get_method_partition().bindings()) { auto* method = pair.first; auto& value = pair.second; if (value.is_top()) { continue; } if (is_boolean(method->get_proto()->get_rtype()) && value.equals(SignedConstantDomain(sign_domain::Interval::GEZ))) { continue; } ++m_stats.constant_methods; } } }
static int bmi_female_validation( int age,int b_cvd,int b_treatedhyp,int b_type2,int ethrisk,int smok,char *errorBuf,int errorBufSize ) { int ok=1; *errorBuf=0; if (!i_in_range(age,30,84)) { ok=0; strlcat(errorBuf,"error: age must be in range (30,84)\n",errorBufSize); } if (!is_boolean(b_cvd)) { ok=0; strlcat(errorBuf,"error: b_cvd must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_treatedhyp)) { ok=0; strlcat(errorBuf,"error: b_treatedhyp must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_type2)) { ok=0; strlcat(errorBuf,"error: b_type2 must be in range (0,1)\n",errorBufSize); } if (!i_in_range(ethrisk,1,9)) { ok=0; strlcat(errorBuf,"error: ethrisk must be in range (1,9)\n",errorBufSize); } if (!is_boolean(smok)) { ok=0; strlcat(errorBuf,"error: smok must be in range (0,1)\n",errorBufSize); } return ok; }
static void mark_boolean (BtorSMTDumpContext * sdc, BtorNodePtrStack * exps) { int i, j, not_bool; BtorNode *cur; /* collect boolean terms */ for (i = 0; i < BTOR_COUNT_STACK (*exps); i++) { cur = BTOR_PEEK_STACK (*exps, i); /* these nodes are boolean by definition */ if (BTOR_IS_BV_EQ_NODE (cur) || BTOR_IS_FUN_EQ_NODE (cur) || BTOR_IS_ULT_NODE (cur) || cur == BTOR_REAL_ADDR_NODE (sdc->btor->true_exp)) { btor_insert_in_ptr_hash_table (sdc->boolean, cur); continue; } else if (BTOR_IS_APPLY_NODE (cur)) { /* boolean function */ if ((BTOR_IS_LAMBDA_NODE (cur->e[0]) && is_boolean (sdc, btor_lambda_get_body (cur->e[0]))) || (BTOR_IS_FUN_COND_NODE (cur->e[0]) && is_boolean (sdc, cur->e[1])) || (BTOR_IS_UF_NODE (cur->e[0]) && btor_is_bool_sort (&sdc->btor->sorts_unique_table, btor_get_codomain_fun_sort ( &sdc->btor->sorts_unique_table, cur->e[0]->sort_id)))) btor_insert_in_ptr_hash_table (sdc->boolean, cur); continue; } else if ((BTOR_IS_AND_NODE (cur) || BTOR_IS_BV_COND_NODE (cur)) && btor_get_exp_width (sdc->btor, cur) == 1) { not_bool = 0; for (j = 0; j < cur->arity; j++) { if (!is_boolean (sdc, cur->e[j])) { not_bool = 1; break; } } if (not_bool) continue; btor_insert_in_ptr_hash_table (sdc->boolean, cur); } } }
static void dump_assert_smt2 (BtorSMTDumpContext * sdc, BtorNode * exp) { assert (sdc); assert (exp); assert (btor_get_exp_width (sdc->btor, exp) == 1); fputs ("(assert ", sdc->file); if (!is_boolean (sdc, exp)) fputs ("(distinct ", sdc->file); recursively_dump_exp_smt (sdc, exp, 0, 0); if (!is_boolean (sdc, exp)) fputs (" #b0)", sdc->file); fputs (")\n", sdc->file); }
static inline bool is_self_evaluating(obj_t expr) { return is_boolean(expr) || is_fixnum(expr) || is_character(expr) || is_string(expr) ; }
bool NetGameEventValue::get_boolean() const { if (is_boolean()) return value_bool; else throw Exception("NetGameEventValue is not a boolean"); }
bool is_self_evaluating(object *exp) { return is_boolean(exp) || is_fixnum(exp) || is_character(exp) || is_empty(exp) || is_string(exp); }
/** * Test that choice_option correctly reports its capabilities. */ TEST(choice_option_test, capabilities) { auto short_name = std::string("f"); auto name = std::string("foo"); auto option = qflags::choice_option(name.c_str(), short_name.c_str(), {"bar", "baz"}, "bar"); EXPECT_EQ(name, option.name()); EXPECT_EQ(short_name, option.short_name()); EXPECT_EQ(false, option.is_set()); EXPECT_EQ(false, option.is_flag()); EXPECT_EQ(false, option.is_command()); EXPECT_EQ(false, option.is_array()); EXPECT_EQ(false, option.is_boolean()); EXPECT_EQ(false, option.is_integer()); EXPECT_EQ(true, option.is_string()); EXPECT_EQ(0u, option.array_size()); EXPECT_THROW(option.value_boolean(), std::logic_error); EXPECT_THROW(option.value_integer(), std::logic_error); EXPECT_EQ("bar", option.value_string()); EXPECT_THROW(option.value_array(0), std::logic_error); EXPECT_THROW(static_cast<bool>(option), std::logic_error); EXPECT_THROW(static_cast<int64_t>(option), std::logic_error); EXPECT_THROW(static_cast<int>(option), std::logic_error); EXPECT_EQ("bar", static_cast<std::string>(option)); }
static bool is_self_evaluating(obj_t *expr) { return (is_boolean(expr) || is_fixnum(expr) || is_character(expr) || is_string(expr) || is_vector(expr) || is_bytevector(expr)); }
bool lua::lua_wrapper::get_boolean(int pos) { if (pos == -1) pos = lua_gettop(L); if (pos == 0) return false; if (is_boolean(pos)) return lua_toboolean(L, pos); if (is_number(pos)) return lua_tonumber(L, pos)==1; return false; }
////////////////////////////////////////////////////// //self_evaluating //number, boolean, string, character and vector object is self-evaluating. ////////////////////////////////////////////////////// static cellpoint is_self_evaluating(cellpoint exp) { if (is_true(is_number(exp)) || is_true(is_boolean(exp)) || is_true(is_null(exp)) || is_true(is_string(exp)) || is_true(is_char(exp)) || is_true(is_vector(exp))){ reg = a_true; }else { reg = a_false; } return reg; }
static int cataract_female_validation( int age,int b_AF,int b_corticosteroids,int b_cvd,int b_ra,int b_type1,int b_type2,double bmi,int ethrisk,int smoke_cat,int statin_user,int surv,char *errorBuf,int errorBufSize ) { int ok=1; *errorBuf=0; if (!i_in_range(age,30,84)) { ok=0; strlcat(errorBuf,"error: age must be in range (30,84)\n",errorBufSize); } if (!is_boolean(b_AF)) { ok=0; strlcat(errorBuf,"error: b_AF must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_corticosteroids)) { ok=0; strlcat(errorBuf,"error: b_corticosteroids must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_cvd)) { ok=0; strlcat(errorBuf,"error: b_cvd must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_ra)) { ok=0; strlcat(errorBuf,"error: b_ra must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_type1)) { ok=0; strlcat(errorBuf,"error: b_type1 must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_type2)) { ok=0; strlcat(errorBuf,"error: b_type2 must be in range (0,1)\n",errorBufSize); } if (!d_in_range(bmi,20,40)) { ok=0; strlcat(errorBuf,"error: bmi must be in range (20,40)\n",errorBufSize); } if (!i_in_range(ethrisk,1,9)) { ok=0; strlcat(errorBuf,"error: ethrisk must be in range (1,9)\n",errorBufSize); } if (!i_in_range(smoke_cat,0,4)) { ok=0; strlcat(errorBuf,"error: smoke_cat must be in range (0,4)\n",errorBufSize); } if (!is_boolean(statin_user)) { ok=0; strlcat(errorBuf,"error: statin_user must be in range (0,1)\n",errorBufSize); } if (!i_in_range(surv,1,5)) { ok=0; strlcat(errorBuf,"error: surv must be in range (1,5)\n",errorBufSize); } return ok; }
static int cvd_female_validation( int b_AF,int b_ra,int b_renal,int b_treatedhyp,int b_type2,double bmi,int ethrisk,int fh_cvd,double rati,double sbp,int smoke_cat,double town,char *errorBuf,int errorBufSize ) { int ok=1; *errorBuf=0; if (!is_boolean(b_AF)) { ok=0; strlcat(errorBuf,"error: b_AF must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_ra)) { ok=0; strlcat(errorBuf,"error: b_ra must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_renal)) { ok=0; strlcat(errorBuf,"error: b_renal must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_treatedhyp)) { ok=0; strlcat(errorBuf,"error: b_treatedhyp must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_type2)) { ok=0; strlcat(errorBuf,"error: b_type2 must be in range (0,1)\n",errorBufSize); } if (!d_in_range(bmi,20,40)) { ok=0; strlcat(errorBuf,"error: bmi must be in range (20,40)\n",errorBufSize); } if (!i_in_range(ethrisk,1,9)) { ok=0; strlcat(errorBuf,"error: ethrisk must be in range (1,9)\n",errorBufSize); } if (!is_boolean(fh_cvd)) { ok=0; strlcat(errorBuf,"error: fh_cvd must be in range (0,1)\n",errorBufSize); } if (!d_in_range(rati,1,12)) { ok=0; strlcat(errorBuf,"error: rati must be in range (1,12)\n",errorBufSize); } if (!d_in_range(sbp,70,210)) { ok=0; strlcat(errorBuf,"error: sbp must be in range (70,210)\n",errorBufSize); } if (!i_in_range(smoke_cat,0,4)) { ok=0; strlcat(errorBuf,"error: smoke_cat must be in range (0,4)\n",errorBufSize); } if (!d_in_range(town,-7,11)) { ok=0; strlcat(errorBuf,"error: town must be in range (-7,11)\n",errorBufSize); } return ok; }
static void dump_let_smt (BtorSMTDumpContext * sdc, BtorNode * exp) { assert (sdc); assert (BTOR_IS_REGULAR_NODE (exp)); assert (!btor_find_in_ptr_hash_table (sdc->dumped, exp)); fputs ("(let (", sdc->file); fputc ('(', sdc->file); dump_smt_id (sdc, exp); // TODO (ma): better symbol for lets? fputc (' ', sdc->file); recursively_dump_exp_smt (sdc, exp, !is_boolean (sdc, exp), 0); fputs ("))", sdc->file); sdc->open_lets++; assert (btor_find_in_ptr_hash_table (sdc->dumped, exp)); }
static void check_arguments(int line, char *args[], int count, mipv6_conf_item_t *item) { int i; for (i = 0; i < count; i++) { switch (item->params[i]) { case MIPV6_PARAM_T_INT: check_argument(is_int(args[i + 1]), "integer", args[0], i, line); break; case MIPV6_PARAM_T_BOOLEAN: check_argument(is_boolean(args[i + 1]), "boolean", args[0], i, line); break; case MIPV6_PARAM_T_ONOFF: check_argument(is_onoff(args[i + 1]), "on/off", args[0], i, line); break; case MIPV6_PARAM_T_IDENTIFIER: check_argument(is_identifier(args[i + 1]), "identifier", args[0], i, line); break; case MIPV6_PARAM_T_ADDRESS: check_argument(is_address(args[i + 1]), "address", args[0], i, line); break; case MIPV6_PARAM_T_PREFIX: check_argument(is_prefix(args[i + 1]), "prefix", args[0], i, line); break; case MIPV6_PARAM_T_DOMAIN: check_argument(is_domain(args[i + 1], 0), "domain name" " or address", args[0], i, line); break; case MIPV6_PARAM_T_NAI: check_argument(is_nai(args[i + 1]), "NAI", args[0], i, line); break; default: break; } } }
bool expression_parser::is_primary_expression(array_t& expression_stack) { any_regular_t result; // empty result used if is_keyword(empty_k) if (is_name(result) || is_token(number_k, result) || is_boolean(result) || is_token(string_k, result) || is_keyword(empty_k)) { expression_stack.push_back(std::move(result)); return true; } else if (is_array(expression_stack)) return true; else if (is_dictionary(expression_stack)) return true; else if (is_variable_or_function(expression_stack)) return true; else if (is_token(open_parenthesis_k)) { require_expression(expression_stack); require_token(close_parenthesis_k); return true; } return false; }
static void dump_fun_let_smt2 (BtorSMTDumpContext * sdc , BtorNode * exp) { assert (sdc); assert (BTOR_IS_REGULAR_NODE (exp)); assert (!btor_find_in_ptr_hash_table (sdc->dumped, exp)); int is_bool; is_bool = is_boolean (sdc, exp); fputs ("(define-fun ", sdc->file); dump_smt_id (sdc, exp); fputs (" () ", sdc->file); // TODO (ma): workaround for now until dump_sort_smt merged from aina if (is_bool) fputs ("Bool", sdc->file); else btor_dump_sort_smt_node (exp, sdc->file); fputc (' ', sdc->file); recursively_dump_exp_smt (sdc, exp, !is_bool, 0); fputs (")\n", sdc->file); assert (btor_find_in_ptr_hash_table (sdc->dumped, exp)); }
static void dump_fun_smt2 (BtorSMTDumpContext * sdc, BtorNode * fun) { assert (fun); assert (sdc); assert (BTOR_IS_REGULAR_NODE (fun)); assert (BTOR_IS_LAMBDA_NODE (fun)); assert (!fun->parameterized); assert (!btor_find_in_ptr_hash_table (sdc->dumped, fun)); int i, refs; BtorNode *cur, *param, *fun_body, *p; BtorMemMgr *mm = sdc->btor->mm; BtorNodePtrStack visit, shared; BtorNodeIterator it, iit; BtorPtrHashTable *mark; BtorPtrHashBucket *b; mark = btor_new_ptr_hash_table (mm, (BtorHashPtr) btor_hash_exp_by_id, (BtorCmpPtr) btor_compare_exp_by_id); BTOR_INIT_STACK (visit); BTOR_INIT_STACK (shared); #if 0 extract_store (sdc, fun, &index, &value, &array); if (index) { assert (value); assert (array); btor_insert_in_ptr_hash_table (sdc->stores, fun); return; } #endif /* collect shared parameterized expressions in function body */ fun_body = btor_lambda_get_body (fun); BTOR_PUSH_STACK (mm, visit, fun_body); while (!BTOR_EMPTY_STACK (visit)) { cur = BTOR_REAL_ADDR_NODE (BTOR_POP_STACK (visit)); if (btor_find_in_ptr_hash_table (mark, cur) || btor_find_in_ptr_hash_table (sdc->dumped, cur) || BTOR_IS_LAMBDA_NODE (cur)) continue; b = btor_find_in_ptr_hash_table (sdc->dump, cur); assert (b); refs = b->data.asInt; /* args and params are handled differently */ /* collect shared parameterized expressions in function body. * arguments, parameters, and constants are excluded. */ if (!BTOR_IS_ARGS_NODE (cur) && !BTOR_IS_PARAM_NODE (cur) /* constants are always printed */ && !BTOR_IS_BV_CONST_NODE (cur) && cur->parameterized && refs > 1) BTOR_PUSH_STACK (mm, shared, cur); btor_insert_in_ptr_hash_table (mark, cur); for (i = 0; i < cur->arity; i++) BTOR_PUSH_STACK (mm, visit, cur->e[i]); } /* dump function signature */ fputs ("(define-fun ", sdc->file); dump_smt_id (sdc, fun); fputs (" (", sdc->file); btor_init_lambda_iterator (&it, fun); while (btor_has_next_lambda_iterator (&it)) { cur = btor_next_lambda_iterator (&it); param = cur->e[0]; if (!btor_find_in_ptr_hash_table (mark, cur)) btor_insert_in_ptr_hash_table (mark, cur); if (!btor_find_in_ptr_hash_table (mark, param)) btor_insert_in_ptr_hash_table (mark, param); btor_insert_in_ptr_hash_table (sdc->dumped, cur); btor_insert_in_ptr_hash_table (sdc->dumped, param); if (fun != cur) fputc (' ', sdc->file); fputc ('(', sdc->file); dump_smt_id (sdc, param); fputc (' ', sdc->file); btor_dump_sort_smt_node (param, sdc->file); fputc (')', sdc->file); } fputs (") ", sdc->file); // TODO (ma): again wait for aina merge for dump_sort_smt if (is_boolean (sdc, fun_body)) fputs ("Bool", sdc->file); else btor_dump_sort_smt_node (fun_body, sdc->file); fputc (' ', sdc->file); assert (sdc->open_lets == 0); /* dump expressions that are shared in 'fun' */ if (shared.start) qsort (shared.start, BTOR_COUNT_STACK (shared), sizeof (BtorNode *), cmp_node_id); for (i = 0; i < BTOR_COUNT_STACK (shared); i++) { cur = BTOR_PEEK_STACK (shared, i); assert (BTOR_IS_REGULAR_NODE (cur)); assert (cur->parameterized); dump_let_smt (sdc, cur); fputc (' ', sdc->file); } recursively_dump_exp_smt (sdc, fun_body, !is_boolean (sdc, fun_body), 0); /* close lets */ for (i = 0; i < sdc->open_lets; i++) fputc (')', sdc->file); sdc->open_lets = 0; /* close define-fun */ fputs (")\n", sdc->file); /* due to lambda hashing it is possible that a lambda in 'fun' is shared in * different functions. hence, we have to check if all lambda parents of * the resp. lambda have already been dumped as otherwise all expressions * below have to be removed from 'sdc->dumped' as they will be dumped * again in a different function definition. */ btor_init_lambda_iterator (&it, fun); while (btor_has_next_lambda_iterator (&it)) { cur = btor_next_lambda_iterator (&it); btor_init_parent_iterator (&iit, cur); while (btor_has_next_parent_iterator (&iit)) { p = btor_next_parent_iterator (&iit); /* find lambda parent that needs to be dumped but has not yet been * dumped */ if (btor_find_in_ptr_hash_table (sdc->dump, p) && !btor_find_in_ptr_hash_table (sdc->dumped, p) && BTOR_IS_LAMBDA_NODE (p)) { BTOR_PUSH_STACK (mm, visit, cur); while (!BTOR_EMPTY_STACK (visit)) { cur = BTOR_REAL_ADDR_NODE (BTOR_POP_STACK (visit)); assert (BTOR_IS_REGULAR_NODE (cur)); if (!cur->parameterized && (!btor_find_in_ptr_hash_table (mark, cur) || !btor_find_in_ptr_hash_table (sdc->dumped, cur))) continue; if (btor_find_in_ptr_hash_table (sdc->dumped, cur)) btor_remove_from_ptr_hash_table (sdc->dumped, cur, 0, 0); for (i = 0; i < cur->arity; i++) BTOR_PUSH_STACK (mm, visit, cur->e[i]); } break; } } } BTOR_RELEASE_STACK (mm, shared); BTOR_RELEASE_STACK (mm, visit); btor_delete_ptr_hash_table (mark); }
static void recursively_dump_exp_smt (BtorSMTDumpContext * sdc, BtorNode * exp, int expect_bv, unsigned depth_limit) { assert (sdc); assert (exp); assert (btor_find_in_ptr_hash_table (sdc->dump, BTOR_REAL_ADDR_NODE (exp))); unsigned depth; int pad, i, is_bool, add_space, zero_extend, expect_bool; BtorBitVector *bitsbv; char *bits; const char *op, *fmt; BtorNode *arg, *real_exp; BtorArgsIterator it; BtorNodePtrStack dump, args; BtorIntStack expect_bv_stack, expect_bool_stack, depth_stack; BtorIntStack add_space_stack, zero_extend_stack; BtorPtrHashTable *visited; BtorMemMgr *mm; mm = sdc->btor->mm; visited = btor_new_ptr_hash_table (mm, 0, 0); BTOR_INIT_STACK (args); BTOR_INIT_STACK (dump); BTOR_INIT_STACK (expect_bv_stack); BTOR_INIT_STACK (expect_bool_stack); BTOR_INIT_STACK (add_space_stack); BTOR_INIT_STACK (zero_extend_stack); BTOR_INIT_STACK (depth_stack); PUSH_DUMP_NODE (exp, expect_bv, 0, 0, 0, 0); while (!BTOR_EMPTY_STACK (dump)) { assert (!BTOR_EMPTY_STACK (expect_bv_stack)); assert (!BTOR_EMPTY_STACK (expect_bool_stack)); assert (!BTOR_EMPTY_STACK (add_space_stack)); assert (!BTOR_EMPTY_STACK (zero_extend_stack)); assert (!BTOR_EMPTY_STACK (depth_stack)); depth = BTOR_POP_STACK (depth_stack); exp = BTOR_POP_STACK (dump); expect_bv = BTOR_POP_STACK (expect_bv_stack); expect_bool = BTOR_POP_STACK (expect_bool_stack); add_space = BTOR_POP_STACK (add_space_stack); zero_extend = BTOR_POP_STACK (zero_extend_stack); real_exp = BTOR_REAL_ADDR_NODE (exp); is_bool = is_boolean (sdc, real_exp); assert (!expect_bv || !expect_bool); assert (!expect_bool || !expect_bv); /* open s-expression */ if (!btor_find_in_ptr_hash_table (visited, real_exp)) { if (add_space) fputc (' ', sdc->file); /* wrap node with zero_extend */ if (zero_extend) { fmt = " ((_ zero_extend %d) "; fprintf (sdc->file, fmt, zero_extend); } /* always print constants */ if (BTOR_IS_BV_CONST_NODE (real_exp)) { if (exp == sdc->btor->true_exp && !expect_bv) fputs ("true", sdc->file); else if (exp == BTOR_INVERT_NODE (sdc->btor->true_exp) && !expect_bv) fputs ("false", sdc->file); else if (BTOR_IS_INVERTED_NODE (exp)) { bitsbv = btor_not_bv ( sdc->btor->mm, btor_const_get_bits (real_exp)); bits = btor_bv_to_char_bv (sdc->btor->mm, bitsbv); dump_const_value_aux_smt (sdc, bits); btor_free_bv (sdc->btor->mm, bitsbv); btor_freestr (sdc->btor->mm, bits); } else { bits = btor_bv_to_char_bv ( sdc->btor->mm, btor_const_get_bits (real_exp)); dump_const_value_aux_smt (sdc, bits); btor_freestr (sdc->btor->mm, bits); } /* close zero extend */ if (zero_extend) fputc (')', sdc->file); continue; } /* wrap non-bool node and make it bool */ if (expect_bool && !is_bool) { fputs ("(= ", sdc->file); dump_const_value_aux_smt (sdc, "1"); fputc (' ', sdc->file); } /* wrap node with bvnot/not */ if (BTOR_IS_INVERTED_NODE (exp)) fputs (expect_bv || !is_bool ? "(bvnot " : "(not ", sdc->file); /* wrap bool node and make it a bit vector expression */ if (is_bool && expect_bv) fputs ("(ite ", sdc->file); if (btor_find_in_ptr_hash_table (sdc->dumped, real_exp) || BTOR_IS_LAMBDA_NODE (real_exp) || BTOR_IS_UF_NODE (real_exp)) { #ifndef NDEBUG BtorPtrHashBucket *b; b = btor_find_in_ptr_hash_table (sdc->dump, real_exp); assert (b); /* functions and variables are declared separately */ assert (BTOR_IS_LAMBDA_NODE (real_exp) || BTOR_IS_UF_NODE (real_exp) || BTOR_IS_BV_VAR_NODE (real_exp) || BTOR_IS_PARAM_NODE (real_exp) || b->data.asInt > 1); #endif dump_smt_id (sdc, exp); goto CLOSE_WRAPPER; } if (depth_limit && depth >= depth_limit) { fprintf (sdc->file, "%s_%d", g_kind2smt[real_exp->kind], real_exp->id); goto CLOSE_WRAPPER; } PUSH_DUMP_NODE (exp, expect_bv, expect_bool, 0, zero_extend, depth); btor_insert_in_ptr_hash_table (visited, real_exp); op = ""; switch (real_exp->kind) { case BTOR_SLL_NODE: case BTOR_SRL_NODE: assert (!is_bool); op = real_exp->kind == BTOR_SRL_NODE ? "bvlshr" : "bvshl"; assert (btor_get_exp_width (sdc->btor, real_exp) > 1); pad = btor_get_exp_width (sdc->btor, real_exp) - btor_get_exp_width (sdc->btor, real_exp->e[1]); PUSH_DUMP_NODE (real_exp->e[1], 1, 0, 1, pad, depth + 1); PUSH_DUMP_NODE (real_exp->e[0], 1, 0, 1, 0, depth + 1); break; case BTOR_BCOND_NODE: op = "ite"; PUSH_DUMP_NODE (real_exp->e[2], !is_bool, 0, 1, 0, depth + 1); PUSH_DUMP_NODE (real_exp->e[1], !is_bool, 0, 1, 0, depth + 1); PUSH_DUMP_NODE (real_exp->e[0], 0, 1, 1, 0, depth + 1); break; case BTOR_APPLY_NODE: /* we need the arguments in reversed order */ btor_init_args_iterator (&it, real_exp->e[1]); while (btor_has_next_args_iterator (&it)) { arg = btor_next_args_iterator (&it); BTOR_PUSH_STACK (mm, args, arg); } while (!BTOR_EMPTY_STACK (args)) { arg = BTOR_POP_STACK (args); // TODO (ma): what about bool arguments/indices PUSH_DUMP_NODE (arg, 1, 0, 1, 0, depth + 1); } PUSH_DUMP_NODE (real_exp->e[0], 1, 0, 0, 0, depth + 1); break; #if 0 case BTOR_LAMBDA_NODE: extract_store (sdc, exp, &index, &value, &array); assert (index); assert (value); assert (array); fputs ("(store ", sdc->file); DUMP_EXP_SMT (array); fputc (' ', sdc->file); DUMP_EXP_SMT (index); fputc (' ', sdc->file); DUMP_EXP_SMT (value); fputc (')', sdc->file); break; #endif default: expect_bv = 1; switch (real_exp->kind) { case BTOR_FEQ_NODE: case BTOR_BEQ_NODE: op = "="; expect_bv = 1; break; case BTOR_ULT_NODE: op = "bvult"; expect_bv = 1; break; case BTOR_SLICE_NODE: assert (!is_bool); op = "(_ extract "; break; case BTOR_AND_NODE: op = is_bool ? "and" : "bvand"; expect_bv = !is_bool; break; case BTOR_ADD_NODE: assert (!is_bool); op = "bvadd"; break; case BTOR_MUL_NODE: assert (!is_bool); op = "bvmul"; break; case BTOR_UDIV_NODE: assert (!is_bool); op = "bvudiv"; break; case BTOR_UREM_NODE: assert (!is_bool); op = "bvurem"; break; case BTOR_CONCAT_NODE: assert (!is_bool); op = "concat"; break; default: assert (0); op = "unknown"; } if (BTOR_IS_AND_NODE (real_exp) && is_bool) { assert (BTOR_EMPTY_STACK (args)); get_children (sdc, exp, &args); for (i = 0; i < BTOR_COUNT_STACK (args); i++) { arg = BTOR_PEEK_STACK (args, i); PUSH_DUMP_NODE (arg, expect_bv, 0, 1, 0, depth + 1); } BTOR_RESET_STACK (args); } else for (i = real_exp->arity - 1; i >= 0; i--) PUSH_DUMP_NODE (real_exp->e[i], expect_bv, 0, 1, 0, depth + 1); } /* open s-expression */ assert (op); fprintf (sdc->file, "(%s", op); if (BTOR_IS_SLICE_NODE (real_exp)) { fmt = "%d %d)"; fprintf (sdc->file, fmt, btor_slice_get_upper (real_exp), btor_slice_get_lower (real_exp)); } } /* close s-expression */ else { if (!btor_find_in_ptr_hash_table (sdc->dumped, real_exp)) btor_insert_in_ptr_hash_table (sdc->dumped, real_exp); /* close s-expression */ if (real_exp->arity > 0) fputc (')', sdc->file); CLOSE_WRAPPER: /* close wrappers */ /* wrap boolean expressions in bit vector expression */ if (is_bool && expect_bv && !BTOR_IS_BV_CONST_NODE (real_exp)) { fputc (' ', sdc->file); dump_const_value_aux_smt (sdc, "1"); fputc (' ', sdc->file); dump_const_value_aux_smt (sdc, "0"); fputc (')', sdc->file); } /* close bvnot for non-constants */ if (BTOR_IS_INVERTED_NODE (exp) && !BTOR_IS_BV_CONST_NODE (real_exp)) fputc (')', sdc->file); /* close bool wrapper */ if (expect_bool && !is_boolean (sdc, real_exp)) fputc (')', sdc->file); /* close zero extend wrapper */ if (zero_extend) fputc (')', sdc->file); } } assert (BTOR_EMPTY_STACK (expect_bv_stack)); BTOR_RELEASE_STACK (mm, args); BTOR_RELEASE_STACK (mm, dump); BTOR_RELEASE_STACK (mm, expect_bv_stack); BTOR_RELEASE_STACK (mm, expect_bool_stack); BTOR_RELEASE_STACK (mm, add_space_stack); BTOR_RELEASE_STACK (mm, zero_extend_stack); BTOR_RELEASE_STACK (mm, depth_stack); btor_delete_ptr_hash_table (visited); }
static int fracture4_female_validation( int age,int alcohol_cat6,int b_antidepressant,int b_anycancer,int b_asthmacopd,int b_corticosteroids,int b_cvd,int b_dementia,int b_endocrine,int b_epilepsy2,int b_falls,int b_fracture4,int b_hrt_oest,int b_liver,int b_malabsorption,int b_parkinsons,int b_ra_sle,int b_renal,int b_type1,int b_type2,double bmi,int ethrisk,int fh_osteoporosis,int smoke_cat,int surv,char *errorBuf,int errorBufSize ) { int ok=1; *errorBuf=0; if (!i_in_range(age,30,100)) { ok=0; strlcat(errorBuf,"error: age must be in range (30,100)\n",errorBufSize); } if (!i_in_range(alcohol_cat6,0,5)) { ok=0; strlcat(errorBuf,"error: alcohol_cat6 must be in range (0,5)\n",errorBufSize); } if (!is_boolean(b_antidepressant)) { ok=0; strlcat(errorBuf,"error: b_antidepressant must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_anycancer)) { ok=0; strlcat(errorBuf,"error: b_anycancer must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_asthmacopd)) { ok=0; strlcat(errorBuf,"error: b_asthmacopd must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_corticosteroids)) { ok=0; strlcat(errorBuf,"error: b_corticosteroids must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_cvd)) { ok=0; strlcat(errorBuf,"error: b_cvd must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_dementia)) { ok=0; strlcat(errorBuf,"error: b_dementia must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_endocrine)) { ok=0; strlcat(errorBuf,"error: b_endocrine must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_epilepsy2)) { ok=0; strlcat(errorBuf,"error: b_epilepsy2 must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_falls)) { ok=0; strlcat(errorBuf,"error: b_falls must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_fracture4)) { ok=0; strlcat(errorBuf,"error: b_fracture4 must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_hrt_oest)) { ok=0; strlcat(errorBuf,"error: b_hrt_oest must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_liver)) { ok=0; strlcat(errorBuf,"error: b_liver must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_malabsorption)) { ok=0; strlcat(errorBuf,"error: b_malabsorption must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_parkinsons)) { ok=0; strlcat(errorBuf,"error: b_parkinsons must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_ra_sle)) { ok=0; strlcat(errorBuf,"error: b_ra_sle must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_renal)) { ok=0; strlcat(errorBuf,"error: b_renal must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_type1)) { ok=0; strlcat(errorBuf,"error: b_type1 must be in range (0,1)\n",errorBufSize); } if (!is_boolean(b_type2)) { ok=0; strlcat(errorBuf,"error: b_type2 must be in range (0,1)\n",errorBufSize); } if (!d_in_range(bmi,20,40)) { ok=0; strlcat(errorBuf,"error: bmi must be in range (20,40)\n",errorBufSize); } if (!i_in_range(ethrisk,1,9)) { ok=0; strlcat(errorBuf,"error: ethrisk must be in range (1,9)\n",errorBufSize); } if (!is_boolean(fh_osteoporosis)) { ok=0; strlcat(errorBuf,"error: fh_osteoporosis must be in range (0,1)\n",errorBufSize); } if (!i_in_range(smoke_cat,0,4)) { ok=0; strlcat(errorBuf,"error: smoke_cat must be in range (0,4)\n",errorBufSize); } if (!i_in_range(surv,1,18)) { ok=0; strlcat(errorBuf,"error: surv must be in range (1,18)\n",errorBufSize); } return ok; }
void write(obj_t obj) { char c; char *str; if (obj == imm_empty_list) { printf("()"); } else if (is_pair(obj)) { printf("("); write_pair(obj); printf(")"); } else if (is_symbol(obj)) { printf("%s", unwrap_symbol(obj)->value); } else if (is_string(obj)) { printf("\"%s\"", unwrap_string(obj)->value); } else if (is_boolean(obj)) { printf("#%c", obj==imm_false ? 'f' : 't'); } else if (is_fixnum(obj)) { printf("%lld", unwrap_fixnum(obj)); } else if (is_thunk(obj)) { printf("#<thunk>"); } else if (is_primitive_proc(obj)) { printf("#<primitive fn>"); } else if (obj == imm_undefined) { printf("#<undefined>"); } else { assert(0); } #if 0 case SYMBOL: printf("%s", obj->data.symbol->value); break; case FIXNUM: printf("%ld", obj->data.fixnum); break; case CHARACTER: c = obj->data.character; printf("#\\"); switch (c) { case '\n': printf("newline"); break; case ' ': printf("space"); break; default: putchar(c); } break; case STRING: str = obj->data.string->value; putchar('"'); while (*str != '\0') { switch (*str) { case '\n': printf("\\n"); break; case '\\': printf("\\\\"); break; case '"': printf("\\\""); break; default: putchar(*str); } str++; } putchar('"'); break; case PAIR: printf("("); write_pair(obj); printf(")"); break; case PRIMITIVE_PROC: case COMPOUND_PROC: printf("#<procedure>"); break; default: fprintf(stderr, "cannot write unknown type\n"); exit(1); }
/// Wrapper around lua_toboolean. /// /// \param index The second parameter to lua_toboolean. /// /// \return The return value of lua_toboolean. bool lutok::state::to_boolean(const int index) { assert(is_boolean(index)); return (lua_toboolean(_pimpl->lua_state, index)==1); }
Type type_check_expr(int oper,Type t1,Type t2) { switch(oper) { case T_EQU: case T_NEQ: if( (is_char(t1) && is_char(t2) ) || (is_string(t1) && is_string(t2) ) || (is_numeric(t1) && is_numeric(t2)) || (is_boolean(t1) && is_boolean(t2)) ) { return BOOLEAN_TYPE; } break; case T_LES: case T_LEQ: case T_GTR: case T_GTE: if( (is_char(t1) && is_char(t2) ) || (is_string(t1) && is_string(t2) ) || (is_numeric(t1) && is_numeric(t2)) ) { return BOOLEAN_TYPE; } break; case T_ADD: case T_SUB: case T_MUL: if( is_numeric(t1) && is_numeric(t2) ) { if(t1>t2) return t1; else return t2; } break; case T_NEG: if( is_numeric(t1) ) { return t1; } break; case T_RDIV: if( is_numeric(t1) && is_numeric(t2) ) { return REAL_TYPE; } break; case T_MOD: case T_IDIV: if( is_integer(t1) && is_integer(t2) ) { return INTEGER_TYPE; } break; case T_OR: case T_AND: if( is_boolean(t1) && is_boolean(t2) ) { return BOOLEAN_TYPE; } break; case T_NOT: if( is_boolean(t1) ) { return BOOLEAN_TYPE; } break; } fatal_error("invalid types in expression\n"); return INTEGER_TYPE; }
int set_result_type(AGENT_RESULT *result, int value_type, int data_type, char *c) { int ret = FAIL; zbx_uint64_t value_uint64; double value_double; assert(result); switch (value_type) { case ITEM_VALUE_TYPE_UINT64: zbx_rtrim(c, " \""); zbx_ltrim(c, " \"+"); del_zeroes(c); switch (data_type) { case ITEM_DATA_TYPE_BOOLEAN: if (SUCCEED == is_boolean(c, &value_uint64)) { SET_UI64_RESULT(result, value_uint64); ret = SUCCEED; } break; case ITEM_DATA_TYPE_OCTAL: if (SUCCEED == is_uoct(c)) { ZBX_OCT2UINT64(value_uint64, c); SET_UI64_RESULT(result, value_uint64); ret = SUCCEED; } break; case ITEM_DATA_TYPE_DECIMAL: if (SUCCEED == is_uint64(c, &value_uint64)) { SET_UI64_RESULT(result, value_uint64); ret = SUCCEED; } break; case ITEM_DATA_TYPE_HEXADECIMAL: if (SUCCEED == is_uhex(c)) { ZBX_HEX2UINT64(value_uint64, c); SET_UI64_RESULT(result, value_uint64); ret = SUCCEED; } else if (SUCCEED == is_hex_string(c)) { zbx_remove_whitespace(c); ZBX_HEX2UINT64(value_uint64, c); SET_UI64_RESULT(result, value_uint64); ret = SUCCEED; } break; default: THIS_SHOULD_NEVER_HAPPEN; break; } break; case ITEM_VALUE_TYPE_FLOAT: zbx_rtrim(c, " \""); zbx_ltrim(c, " \"+"); if (SUCCEED != is_double(c)) break; value_double = atof(c); SET_DBL_RESULT(result, value_double); ret = SUCCEED; break; case ITEM_VALUE_TYPE_STR: zbx_replace_invalid_utf8(c); SET_STR_RESULT(result, zbx_strdup(NULL, c)); ret = SUCCEED; break; case ITEM_VALUE_TYPE_TEXT: zbx_replace_invalid_utf8(c); SET_TEXT_RESULT(result, zbx_strdup(NULL, c)); ret = SUCCEED; break; case ITEM_VALUE_TYPE_LOG: zbx_replace_invalid_utf8(c); add_log_result(result, c); ret = SUCCEED; break; } if (SUCCEED != ret) { char *error = NULL; zbx_remove_chars(c, "\r\n"); zbx_replace_invalid_utf8(c); if (ITEM_VALUE_TYPE_UINT64 == value_type) error = zbx_dsprintf(error, "Received value [%s] is not suitable for value type [%s] and data type [%s]", c, zbx_item_value_type_string(value_type), zbx_item_data_type_string(data_type)); else error = zbx_dsprintf(error, "Received value [%s] is not suitable for value type [%s]", c, zbx_item_value_type_string(value_type)); SET_MSG_RESULT(result, error); } return ret; }
object *is_boolean_proc(object *arguments) { return is_boolean(car(arguments)) ? true : false; }
/**** Identification ****/ static inline int is_self_evaluating(object *exp) { return is_number(exp) || is_boolean(exp) || is_character(exp) || is_string(exp); }
void check_arg_type(char *func, char* loc, cellpoint arg, int type) { switch (type){ case BOOLEAN_T: if (is_false(is_boolean(arg))){ printf("Error: procedure \"%s\" expects the %s argument is a boolean, but given: ", func, loc); write(arg); newline(); error_handler(); } break; case CHARACTER_T: if (is_false(is_char(arg))){ printf("Errror: procedure \"%s\" expects the %s argument is a character, but given: ", func, loc); write(arg); newline(); error_handler(); } break; case INTEGER_T: if (is_false(is_integer(arg))){ printf("Error: procedure \"%s\" expects the %s argument is a integer, but given: ", func, loc); write(arg); newline(); error_handler(); } break; case NUMBER_T: if (is_false(is_number(arg))){ printf("Error: procedure \"%s\" expects the %s argument is a number, but given: ", func, loc); write(arg); newline(); error_handler(); } break; case SYMBOL_T: if (is_false(is_symbol(arg))){ printf("Error: procedure \"%s\" expects the %s argument is a symbol, but given: ", func, loc); write(arg); newline(); error_handler(); } break; case STRING_T: if (is_false(is_string(arg))){ printf("Error: procedure \"%s\" expects the %s argument is a string, but given: ", func, loc); write(arg); newline(); error_handler(); } break; case VECTOR_T: if (is_false(is_vector(arg))){ printf("Error: procedure \"%s\" expects the %s argument is a vector, but given: ", func, loc); write(arg); newline(); error_handler(); } break; case PAIR_T: if (is_false(is_pair(arg))){ printf("Error: procedure \"%s\" expects the %s argument is a pair, but given: ", func, loc); write(arg); newline(); error_handler(); } break; case LIST_T: if (is_false(is_list(arg))){ printf("Error: procedure \"%s\" expects the %s argument is a list, but given: ", func, loc); write(arg); newline(); error_handler(); } break; case PROCEDURE_T: if (is_false(is_procedure(arg))){ printf("Error: procedure \"%s\" expects the %s argument is a procedure, but given: ", func, loc); write(arg); newline(); error_handler(); } break; default: printf("Error: unknown check arg type. -- CHECK_ARG_TYPE.\n"); error_handler(); } }
object *is_boolean_proc(object *arguments) { return make_boolean(is_boolean(car(arguments))); }